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

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

Issue 1543533002: Restore non-static CLD data functionality. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebase Created 4 years, 11 months 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
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 "build/build_config.h" 13 #include "build/build_config.h"
14 #include "chrome/browser/browser_process.h" 14 #include "chrome/browser/browser_process.h"
15 #include "chrome/browser/chrome_notification_types.h" 15 #include "chrome/browser/chrome_notification_types.h"
16 #include "chrome/browser/infobars/infobar_service.h" 16 #include "chrome/browser/infobars/infobar_service.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/translate/translate_accept_languages_factory.h" 18 #include "chrome/browser/translate/translate_accept_languages_factory.h"
19 #include "chrome/browser/translate/translate_service.h" 19 #include "chrome/browser/translate/translate_service.h"
20 #include "chrome/browser/ui/browser.h" 20 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_finder.h" 21 #include "chrome/browser/ui/browser_finder.h"
22 #include "chrome/browser/ui/browser_tabstrip.h" 22 #include "chrome/browser/ui/browser_tabstrip.h"
23 #include "chrome/browser/ui/browser_window.h" 23 #include "chrome/browser/ui/browser_window.h"
24 #include "chrome/browser/ui/tabs/tab_strip_model.h" 24 #include "chrome/browser/ui/tabs/tab_strip_model.h"
25 #include "chrome/browser/ui/translate/translate_bubble_factory.h" 25 #include "chrome/browser/ui/translate/translate_bubble_factory.h"
26 #include "chrome/common/chrome_paths.h" 26 #include "chrome/common/chrome_paths.h"
27 #include "chrome/common/pref_names.h" 27 #include "chrome/common/pref_names.h"
28 #include "components/translate/content/browser/browser_cld_data_provider_factory .h"
29 #include "components/translate/content/common/cld_data_source.h" 28 #include "components/translate/content/common/cld_data_source.h"
30 #include "components/translate/content/common/translate_messages.h" 29 #include "components/translate/content/common/translate_messages.h"
31 #include "components/translate/core/browser/language_state.h" 30 #include "components/translate/core/browser/language_state.h"
32 #include "components/translate/core/browser/page_translated_details.h" 31 #include "components/translate/core/browser/page_translated_details.h"
33 #include "components/translate/core/browser/translate_accept_languages.h" 32 #include "components/translate/core/browser/translate_accept_languages.h"
34 #include "components/translate/core/browser/translate_download_manager.h" 33 #include "components/translate/core/browser/translate_download_manager.h"
35 #include "components/translate/core/browser/translate_infobar_delegate.h" 34 #include "components/translate/core/browser/translate_infobar_delegate.h"
36 #include "components/translate/core/browser/translate_manager.h" 35 #include "components/translate/core/browser/translate_manager.h"
37 #include "components/translate/core/browser/translate_prefs.h" 36 #include "components/translate/core/browser/translate_prefs.h"
38 #include "components/translate/core/common/language_detection_details.h" 37 #include "components/translate/core/common/language_detection_details.h"
(...skipping 15 matching lines...) Expand all
54 bool g_cld_file_path_initialized_ = false; 53 bool g_cld_file_path_initialized_ = false;
55 54
56 } // namespace 55 } // namespace
57 56
58 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeTranslateClient); 57 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeTranslateClient);
59 58
60 ChromeTranslateClient::ChromeTranslateClient(content::WebContents* web_contents) 59 ChromeTranslateClient::ChromeTranslateClient(content::WebContents* web_contents)
61 : content::WebContentsObserver(web_contents), 60 : content::WebContentsObserver(web_contents),
62 translate_driver_(&web_contents->GetController()), 61 translate_driver_(&web_contents->GetController()),
63 translate_manager_( 62 translate_manager_(
64 new translate::TranslateManager(this, prefs::kAcceptLanguages)), 63 new translate::TranslateManager(this, prefs::kAcceptLanguages)) {
65 cld_data_provider_(
66 translate::BrowserCldDataProviderFactory::Get()->
67 CreateBrowserCldDataProvider(web_contents)) {
68 translate_driver_.AddObserver(this); 64 translate_driver_.AddObserver(this);
69 translate_driver_.set_translate_manager(translate_manager_.get()); 65 translate_driver_.set_translate_manager(translate_manager_.get());
70 // Customization: for the standalone data source, we configure the path to 66 // Customization: for the standalone data source, we configure the path to
71 // CLD data immediately on startup. 67 // CLD data immediately on startup.
68 // TODO(andrewhayden): This belongs in the data source implementation, not
69 // here.
72 if (translate::CldDataSource::IsUsingStandaloneDataSource() && 70 if (translate::CldDataSource::IsUsingStandaloneDataSource() &&
73 !g_cld_file_path_initialized_) { 71 !g_cld_file_path_initialized_) {
74 DVLOG(1) << "Initializing CLD file path for the first time."; 72 DVLOG(1) << "Initializing CLD file path for the first time.";
75 base::FilePath path; 73 base::FilePath path;
76 if (!PathService::Get(chrome::DIR_USER_DATA, &path)) { 74 if (!PathService::Get(chrome::DIR_USER_DATA, &path)) {
77 // Chrome isn't properly installed 75 // Chrome isn't properly installed
78 LOG(WARNING) << "Unable to locate user data directory"; 76 LOG(WARNING) << "Unable to locate user data directory";
79 } else { 77 } else {
80 g_cld_file_path_initialized_ = true; 78 g_cld_file_path_initialized_ = true;
81 path = path.Append(kCldDataFileName); 79 path = path.Append(kCldDataFileName);
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 if (!browser) { 266 if (!browser) {
269 NOTREACHED(); 267 NOTREACHED();
270 return; 268 return;
271 } 269 }
272 270
273 chrome::AddSelectedTabWithURL( 271 chrome::AddSelectedTabWithURL(
274 browser, report_url, ui::PAGE_TRANSITION_AUTO_BOOKMARK); 272 browser, report_url, ui::PAGE_TRANSITION_AUTO_BOOKMARK);
275 #endif // defined(OS_ANDROID) 273 #endif // defined(OS_ANDROID)
276 } 274 }
277 275
278 bool ChromeTranslateClient::OnMessageReceived(const IPC::Message& message) {
279 return cld_data_provider_->OnMessageReceived(message);
280 }
281
282 void ChromeTranslateClient::WebContentsDestroyed() { 276 void ChromeTranslateClient::WebContentsDestroyed() {
283 // Translation process can be interrupted. 277 // Translation process can be interrupted.
284 // Destroying the TranslateManager now guarantees that it never has to deal 278 // Destroying the TranslateManager now guarantees that it never has to deal
285 // with NULL WebContents. 279 // with NULL WebContents.
286 translate_manager_.reset(); 280 translate_manager_.reset();
287 } 281 }
288 282
289 // ContentTranslateDriver::Observer implementation. 283 // ContentTranslateDriver::Observer implementation.
290 284
291 void ChromeTranslateClient::OnLanguageDetermined( 285 void ChromeTranslateClient::OnLanguageDetermined(
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 if (GetLanguageState().InTranslateNavigation()) 342 if (GetLanguageState().InTranslateNavigation())
349 return; 343 return;
350 } 344 }
351 345
352 TranslateBubbleFactory::Show( 346 TranslateBubbleFactory::Show(
353 browser->window(), web_contents(), step, error_type); 347 browser->window(), web_contents(), step, error_type);
354 #else 348 #else
355 NOTREACHED(); 349 NOTREACHED();
356 #endif 350 #endif
357 } 351 }
OLDNEW
« no previous file with comments | « chrome/browser/translate/chrome_translate_client.h ('k') | components/translate/content/browser/content_translate_driver.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698