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

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

Issue 2034413003: Delete the non-static CLD data source logic. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase to latest master Created 4 years, 6 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/strings/string_split.h" 11 #include "base/strings/string_split.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "chrome/browser/browser_process.h" 13 #include "chrome/browser/browser_process.h"
14 #include "chrome/browser/chrome_notification_types.h" 14 #include "chrome/browser/chrome_notification_types.h"
15 #include "chrome/browser/infobars/infobar_service.h" 15 #include "chrome/browser/infobars/infobar_service.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/browser/translate/translate_accept_languages_factory.h" 17 #include "chrome/browser/translate/translate_accept_languages_factory.h"
18 #include "chrome/browser/translate/translate_service.h" 18 #include "chrome/browser/translate/translate_service.h"
19 #include "chrome/browser/ui/browser.h" 19 #include "chrome/browser/ui/browser.h"
20 #include "chrome/browser/ui/browser_finder.h" 20 #include "chrome/browser/ui/browser_finder.h"
21 #include "chrome/browser/ui/browser_tabstrip.h" 21 #include "chrome/browser/ui/browser_tabstrip.h"
22 #include "chrome/browser/ui/browser_window.h" 22 #include "chrome/browser/ui/browser_window.h"
23 #include "chrome/browser/ui/tabs/tab_strip_model.h" 23 #include "chrome/browser/ui/tabs/tab_strip_model.h"
24 #include "chrome/browser/ui/translate/translate_bubble_factory.h" 24 #include "chrome/browser/ui/translate/translate_bubble_factory.h"
25 #include "chrome/common/chrome_paths.h" 25 #include "chrome/common/chrome_paths.h"
26 #include "chrome/common/pref_names.h" 26 #include "chrome/common/pref_names.h"
27 #include "components/prefs/pref_service.h" 27 #include "components/prefs/pref_service.h"
28 #include "components/translate/content/common/cld_data_source.h"
29 #include "components/translate/content/common/translate_messages.h" 28 #include "components/translate/content/common/translate_messages.h"
30 #include "components/translate/core/browser/language_state.h" 29 #include "components/translate/core/browser/language_state.h"
31 #include "components/translate/core/browser/page_translated_details.h" 30 #include "components/translate/core/browser/page_translated_details.h"
32 #include "components/translate/core/browser/translate_accept_languages.h" 31 #include "components/translate/core/browser/translate_accept_languages.h"
33 #include "components/translate/core/browser/translate_download_manager.h" 32 #include "components/translate/core/browser/translate_download_manager.h"
34 #include "components/translate/core/browser/translate_infobar_delegate.h" 33 #include "components/translate/core/browser/translate_infobar_delegate.h"
35 #include "components/translate/core/browser/translate_manager.h" 34 #include "components/translate/core/browser/translate_manager.h"
36 #include "components/translate/core/browser/translate_prefs.h" 35 #include "components/translate/core/browser/translate_prefs.h"
37 #include "components/translate/core/common/language_detection_details.h" 36 #include "components/translate/core/common/language_detection_details.h"
38 #include "components/variations/service/variations_service.h" 37 #include "components/variations/service/variations_service.h"
39 #include "content/public/browser/notification_service.h" 38 #include "content/public/browser/notification_service.h"
40 #include "content/public/browser/render_view_host.h" 39 #include "content/public/browser/render_view_host.h"
41 #include "content/public/browser/web_contents.h" 40 #include "content/public/browser/web_contents.h"
42 #include "grit/theme_resources.h" 41 #include "grit/theme_resources.h"
43 #include "url/gurl.h" 42 #include "url/gurl.h"
44 43
45 namespace {
46
47 // TODO(andrewhayden): Make the data file path into a gyp/gn define
48 // If you change this, also update standalone_cld_data_harness.cc
49 // accordingly!
50 const base::FilePath::CharType kCldDataFileName[] =
51 FILE_PATH_LITERAL("cld2_data.bin");
52
53 bool g_cld_file_path_initialized_ = false;
54
55 } // namespace
56
57 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeTranslateClient); 44 DEFINE_WEB_CONTENTS_USER_DATA_KEY(ChromeTranslateClient);
58 45
59 ChromeTranslateClient::ChromeTranslateClient(content::WebContents* web_contents) 46 ChromeTranslateClient::ChromeTranslateClient(content::WebContents* web_contents)
60 : content::WebContentsObserver(web_contents), 47 : content::WebContentsObserver(web_contents),
61 translate_driver_(&web_contents->GetController()), 48 translate_driver_(&web_contents->GetController()),
62 translate_manager_( 49 translate_manager_(
63 new translate::TranslateManager(this, prefs::kAcceptLanguages)) { 50 new translate::TranslateManager(this, prefs::kAcceptLanguages)) {
64 translate_driver_.AddObserver(this); 51 translate_driver_.AddObserver(this);
65 translate_driver_.set_translate_manager(translate_manager_.get()); 52 translate_driver_.set_translate_manager(translate_manager_.get());
66 // Customization: for the standalone data source, we configure the path to
67 // CLD data immediately on startup.
68 // TODO(andrewhayden): This belongs in the data source implementation, not
69 // here.
70 if (translate::CldDataSource::IsUsingStandaloneDataSource() &&
71 !g_cld_file_path_initialized_) {
72 DVLOG(1) << "Initializing CLD file path for the first time.";
73 base::FilePath path;
74 if (!PathService::Get(chrome::DIR_USER_DATA, &path)) {
75 // Chrome isn't properly installed
76 LOG(WARNING) << "Unable to locate user data directory";
77 } else {
78 g_cld_file_path_initialized_ = true;
79 path = path.Append(kCldDataFileName);
80 DVLOG(1) << "Setting CLD data file path: " << path.value();
81 translate::CldDataSource::Get()->SetCldDataFilePath(path);
82 }
83 }
84 } 53 }
85 54
86 ChromeTranslateClient::~ChromeTranslateClient() { 55 ChromeTranslateClient::~ChromeTranslateClient() {
87 translate_driver_.RemoveObserver(this); 56 translate_driver_.RemoveObserver(this);
88 } 57 }
89 58
90 translate::LanguageState& ChromeTranslateClient::GetLanguageState() { 59 translate::LanguageState& ChromeTranslateClient::GetLanguageState() {
91 return translate_manager_->GetLanguageState(); 60 return translate_manager_->GetLanguageState();
92 } 61 }
93 62
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 if (GetLanguageState().InTranslateNavigation()) 309 if (GetLanguageState().InTranslateNavigation())
341 return; 310 return;
342 } 311 }
343 312
344 TranslateBubbleFactory::Show(browser->window(), web_contents(), step, 313 TranslateBubbleFactory::Show(browser->window(), web_contents(), step,
345 error_type); 314 error_type);
346 #else 315 #else
347 NOTREACHED(); 316 NOTREACHED();
348 #endif 317 #endif
349 } 318 }
OLDNEW
« no previous file with comments | « chrome/browser/resources/translate_internals/prefs.html ('k') | chrome/browser/translate/cld_data_harness.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698