#ifndef CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_
#define CHROME_BROWSER_TRANSLATE_TRANSLATE_MANAGER_H_
#include <map>
#include <string>
#include <vector>
#include "base/callback_list.h"
#include "base/gtest_prod_util.h"
#include "base/memory/scoped_ptr.h"
#include "base/memory/weak_ptr.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
class GURL;
struct PageTranslatedDetails;
class PrefService;
class TranslateClient;
class TranslateDriver;
struct TranslateErrorDetails;
class TranslateTabHelper;
namespace content {
class WebContents;
}
class TranslateManager : public content::NotificationObserver {
public:
TranslateManager(TranslateTabHelper* helper,
const std::string& accept_language_pref_name);
virtual ~TranslateManager();
static bool IsTranslatableURL(const GURL& url);
static std::string GetTargetLanguage(
const std::vector<std::string>& accept_languages_list);
static std::string GetAutoTargetLanguage(const std::string& original_language,
PrefService* prefs);
void TranslatePage(const std::string& source_lang,
const std::string& target_lang,
bool triggered_from_menu);
void RevertTranslation();
void ReportLanguageDetectionError();
virtual void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) OVERRIDE;
void set_translate_max_reload_attemps(int attempts) {
max_reload_check_attempts_ = attempts;
}
typedef base::Callback<void(const TranslateErrorDetails&)>
TranslateErrorCallback;
typedef base::CallbackList<void(const TranslateErrorDetails&)>
TranslateErrorCallbackList;
static scoped_ptr<TranslateErrorCallbackList::Subscription>
RegisterTranslateErrorCallback(const TranslateErrorCallback& callback);
private:
void InitiateTranslation(const std::string& page_lang);
void InitiateTranslationPosted(const std::string& page_lang, int attempt);
void DoTranslatePage(const std::string& translate_script,
const std::string& source_lang,
const std::string& target_lang);
void PageTranslated(PageTranslatedDetails* details);
void OnTranslateScriptFetchComplete(int page_id,
const std::string& source_lang,
const std::string& target_lang,
bool success,
const std::string& data);
content::NotificationRegistrar notification_registrar_;
int max_reload_check_attempts_;
std::string accept_languages_pref_name_;
TranslateTabHelper* translate_tab_helper_;
TranslateClient* translate_client_;
TranslateDriver* translate_driver_;
base::WeakPtrFactory<TranslateManager> weak_method_factory_;
DISALLOW_COPY_AND_ASSIGN(TranslateManager);
};
#endif