Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(359)

Side by Side Diff: chrome/browser/translate/chrome_translate_client.cc

Issue 461633002: Refactor language detection logic to allow non-static CLD data sources. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make some of the harness factory methods private Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/translate/chrome_translate_client.h" 5 #include "chrome/browser/translate/chrome_translate_client.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/prefs/pref_service.h" 11 #include "base/prefs/pref_service.h"
12 #include "base/strings/string_split.h" 12 #include "base/strings/string_split.h"
13 #include "chrome/browser/chrome_notification_types.h" 13 #include "chrome/browser/chrome_notification_types.h"
14 #include "chrome/browser/infobars/infobar_service.h" 14 #include "chrome/browser/infobars/infobar_service.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/translate/translate_accept_languages_factory.h" 16 #include "chrome/browser/translate/translate_accept_languages_factory.h"
17 #include "chrome/browser/translate/translate_service.h" 17 #include "chrome/browser/translate/translate_service.h"
18 #include "chrome/browser/ui/browser.h" 18 #include "chrome/browser/ui/browser.h"
19 #include "chrome/browser/ui/browser_finder.h" 19 #include "chrome/browser/ui/browser_finder.h"
20 #include "chrome/browser/ui/browser_tabstrip.h" 20 #include "chrome/browser/ui/browser_tabstrip.h"
21 #include "chrome/browser/ui/browser_window.h" 21 #include "chrome/browser/ui/browser_window.h"
22 #include "chrome/browser/ui/tabs/tab_strip_model.h" 22 #include "chrome/browser/ui/tabs/tab_strip_model.h"
23 #include "chrome/browser/ui/translate/translate_bubble_factory.h" 23 #include "chrome/browser/ui/translate/translate_bubble_factory.h"
24 #include "chrome/common/chrome_paths.h" 24 #include "chrome/common/chrome_paths.h"
25 #include "chrome/common/pref_names.h" 25 #include "chrome/common/pref_names.h"
26 #include "components/infobars/core/infobar.h" 26 #include "components/infobars/core/infobar.h"
27 #include "components/translate/content/browser/browser_cld_data_provider_factory .h"
27 #include "components/translate/content/common/cld_data_source.h" 28 #include "components/translate/content/common/cld_data_source.h"
28 #include "components/translate/content/common/translate_messages.h" 29 #include "components/translate/content/common/translate_messages.h"
29 #include "components/translate/core/browser/language_state.h" 30 #include "components/translate/core/browser/language_state.h"
30 #include "components/translate/core/browser/page_translated_details.h" 31 #include "components/translate/core/browser/page_translated_details.h"
31 #include "components/translate/core/browser/translate_accept_languages.h" 32 #include "components/translate/core/browser/translate_accept_languages.h"
32 #include "components/translate/core/browser/translate_download_manager.h" 33 #include "components/translate/core/browser/translate_download_manager.h"
33 #include "components/translate/core/browser/translate_infobar_delegate.h" 34 #include "components/translate/core/browser/translate_infobar_delegate.h"
34 #include "components/translate/core/browser/translate_manager.h" 35 #include "components/translate/core/browser/translate_manager.h"
35 #include "components/translate/core/browser/translate_prefs.h" 36 #include "components/translate/core/browser/translate_prefs.h"
36 #include "components/translate/core/common/language_detection_details.h" 37 #include "components/translate/core/common/language_detection_details.h"
(...skipping 16 matching lines...) Expand all
53 } // namespace 54 } // namespace
54 55
55 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeTranslateClient); 56 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeTranslateClient);
56 57
57 ChromeTranslateClient::ChromeTranslateClient(content::WebContents* web_contents) 58 ChromeTranslateClient::ChromeTranslateClient(content::WebContents* web_contents)
58 : content::WebContentsObserver(web_contents), 59 : content::WebContentsObserver(web_contents),
59 translate_driver_(&web_contents->GetController()), 60 translate_driver_(&web_contents->GetController()),
60 translate_manager_( 61 translate_manager_(
61 new translate::TranslateManager(this, prefs::kAcceptLanguages)), 62 new translate::TranslateManager(this, prefs::kAcceptLanguages)),
62 cld_data_provider_( 63 cld_data_provider_(
63 translate::CreateBrowserCldDataProviderFor(web_contents)) { 64 translate::BrowserCldDataProviderFactory::Get()->
65 CreateBrowserCldDataProvider(web_contents)) {
64 translate_driver_.AddObserver(this); 66 translate_driver_.AddObserver(this);
65 translate_driver_.set_translate_manager(translate_manager_.get()); 67 translate_driver_.set_translate_manager(translate_manager_.get());
66 // Customization: for the standalone data source, we configure the path to 68 // Customization: for the standalone data source, we configure the path to
67 // CLD data immediately on startup. 69 // CLD data immediately on startup.
68 if (translate::CldDataSource::ShouldUseStandaloneDataFile() && 70 if (translate::CldDataSource::IsUsingStandaloneDataSource() &&
69 !g_cld_file_path_initialized_) { 71 !g_cld_file_path_initialized_) {
70 DVLOG(1) << "Initializing CLD file path for the first time."; 72 DVLOG(1) << "Initializing CLD file path for the first time.";
71 base::FilePath path; 73 base::FilePath path;
72 if (!PathService::Get(chrome::DIR_USER_DATA, &path)) { 74 if (!PathService::Get(chrome::DIR_USER_DATA, &path)) {
73 // Chrome isn't properly installed 75 // Chrome isn't properly installed
74 LOG(WARNING) << "Unable to locate user data directory"; 76 LOG(WARNING) << "Unable to locate user data directory";
75 } else { 77 } else {
76 g_cld_file_path_initialized_ = true; 78 g_cld_file_path_initialized_ = true;
77 path = path.Append(kCldDataFileName); 79 path = path.Append(kCldDataFileName);
78 DVLOG(1) << "Setting CLD data file path: " << path.value(); 80 DVLOG(1) << "Setting CLD data file path: " << path.value();
79 translate::SetCldDataFilePath(path); 81 translate::CldDataSource::Get()->SetCldDataFilePath(path);
80 } 82 }
81 } 83 }
82 } 84 }
83 85
84 ChromeTranslateClient::~ChromeTranslateClient() { 86 ChromeTranslateClient::~ChromeTranslateClient() {
85 translate_driver_.RemoveObserver(this); 87 translate_driver_.RemoveObserver(this);
86 } 88 }
87 89
88 translate::LanguageState& ChromeTranslateClient::GetLanguageState() { 90 translate::LanguageState& ChromeTranslateClient::GetLanguageState() {
89 return translate_manager_->GetLanguageState(); 91 return translate_manager_->GetLanguageState();
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
337 if (GetLanguageState().InTranslateNavigation()) 339 if (GetLanguageState().InTranslateNavigation())
338 return; 340 return;
339 } 341 }
340 342
341 TranslateBubbleFactory::Show( 343 TranslateBubbleFactory::Show(
342 browser->window(), web_contents(), step, error_type); 344 browser->window(), web_contents(), step, error_type);
343 #else 345 #else
344 NOTREACHED(); 346 NOTREACHED();
345 #endif 347 #endif
346 } 348 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/chromeos/chromevox/chromevox_tests.gypi ('k') | chrome/browser/translate/cld_data_harness.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698