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

Side by Side Diff: chrome/browser/component_updater/cld_component_installer.cc

Issue 333603002: Modularize Compact Language Detector 2 (CLD2) data sources (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: merge https://codereview.chromium.org/326383005 Created 6 years, 5 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 | 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/component_updater/cld_component_installer.h" 5 #include "chrome/browser/component_updater/cld_component_installer.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/lazy_instance.h" 13 #include "base/lazy_instance.h"
14 #include "base/logging.h" 14 #include "base/logging.h"
15 #include "base/path_service.h" 15 #include "base/path_service.h"
16 #include "chrome/browser/profiles/profile.h" 16 #include "chrome/browser/profiles/profile.h"
17 #include "chrome/common/chrome_constants.h"
18 #include "chrome/common/chrome_paths.h" 17 #include "chrome/common/chrome_paths.h"
18 #include "components/translate/content/browser/data_file_browser_cld_data_provid er.h"
19 #include "content/public/browser/browser_thread.h" 19 #include "content/public/browser/browser_thread.h"
20 #include "net/ssl/ssl_config_service.h" 20 #include "net/ssl/ssl_config_service.h"
21 21
22 using component_updater::ComponentUpdateService; 22 using component_updater::ComponentUpdateService;
23 using content::BrowserThread; 23 using content::BrowserThread;
24 24
25 namespace { 25 namespace {
26 26 // TODO(andrewhayden): Make the data file path into a gyp/gn define
27 // Once we have acquired a valid file from the component installer, we need to 27 // If you change this, also update component_cld_data_harness.cc
28 // make the path available to other parts of the system such as the 28 // and cld_component_installer_unittest.cc accordingly!
29 // translation libraries. We create a global to hold onto the path, and a 29 const base::FilePath::CharType kCldDataFileName[] =
30 // lock to guard it. See GetLatestCldDataFile(...) for more info. 30 FILE_PATH_LITERAL("cld2_data.bin");
31 base::LazyInstance<base::Lock> cld_file_lock = LAZY_INSTANCE_INITIALIZER; 31 } // namespace
32 base::LazyInstance<base::FilePath> cld_file = LAZY_INSTANCE_INITIALIZER;
33
34 }
35 32
36 namespace component_updater { 33 namespace component_updater {
37 34
38 // The SHA256 of the SubjectPublicKeyInfo used to sign the extension. 35 // The SHA256 of the SubjectPublicKeyInfo used to sign the extension.
39 // The extension id is: dpedmmgabcgnikllifiidmijgoiihfgf 36 // The extension id is: dpedmmgabcgnikllifiidmijgoiihfgf
40 const uint8 kPublicKeySHA256[32] = { 37 const uint8 kPublicKeySHA256[32] = {
41 0x3f, 0x43, 0xcc, 0x60, 0x12, 0x6d, 0x8a, 0xbb, 38 0x3f, 0x43, 0xcc, 0x60, 0x12, 0x6d, 0x8a, 0xbb,
42 0x85, 0x88, 0x3c, 0x89, 0x6e, 0x88, 0x75, 0x65, 39 0x85, 0x88, 0x3c, 0x89, 0x6e, 0x88, 0x75, 0x65,
43 0xb9, 0x46, 0x09, 0xe8, 0xca, 0x92, 0xdd, 0x82, 40 0xb9, 0x46, 0x09, 0xe8, 0xca, 0x92, 0xdd, 0x82,
44 0x4e, 0x6d, 0x0e, 0xe6, 0x79, 0x8a, 0x87, 0xf5 41 0x4e, 0x6d, 0x0e, 0xe6, 0x79, 0x8a, 0x87, 0xf5
(...skipping 14 matching lines...) Expand all
59 return true; // Nothing custom here. 56 return true; // Nothing custom here.
60 } 57 }
61 58
62 base::FilePath CldComponentInstallerTraits::GetInstalledPath( 59 base::FilePath CldComponentInstallerTraits::GetInstalledPath(
63 const base::FilePath& base) { 60 const base::FilePath& base) {
64 // Currently, all platforms have the file at the same location because there 61 // Currently, all platforms have the file at the same location because there
65 // is no binary difference in the generated file on any supported platform. 62 // is no binary difference in the generated file on any supported platform.
66 // NB: This may change when 64-bit is officially supported. 63 // NB: This may change when 64-bit is officially supported.
67 return base.Append(FILE_PATH_LITERAL("_platform_specific")) 64 return base.Append(FILE_PATH_LITERAL("_platform_specific"))
68 .Append(FILE_PATH_LITERAL("all")) 65 .Append(FILE_PATH_LITERAL("all"))
69 .Append(chrome::kCLDDataFilename); 66 .Append(kCldDataFileName);
70 } 67 }
71 68
72 void CldComponentInstallerTraits::ComponentReady( 69 void CldComponentInstallerTraits::ComponentReady(
73 const base::Version& version, 70 const base::Version& version,
74 const base::FilePath& path, 71 const base::FilePath& path,
75 scoped_ptr<base::DictionaryValue> manifest) { 72 scoped_ptr<base::DictionaryValue> manifest) {
76 VLOG(1) << "Component ready, version " << version.GetString() << " in " 73 VLOG(1) << "Component ready, version " << version.GetString() << " in "
77 << path.value(); 74 << path.value();
78 SetLatestCldDataFile(GetInstalledPath(path)); 75 SetLatestCldDataFile(GetInstalledPath(path));
79 } 76 }
(...skipping 30 matching lines...) Expand all
110 new CldComponentInstallerTraits()); 107 new CldComponentInstallerTraits());
111 // |cus| will take ownership of |installer| during installer->Register(cus). 108 // |cus| will take ownership of |installer| during installer->Register(cus).
112 DefaultComponentInstaller* installer = 109 DefaultComponentInstaller* installer =
113 new DefaultComponentInstaller(traits.Pass()); 110 new DefaultComponentInstaller(traits.Pass());
114 installer->Register(cus); 111 installer->Register(cus);
115 } 112 }
116 113
117 void CldComponentInstallerTraits::SetLatestCldDataFile( 114 void CldComponentInstallerTraits::SetLatestCldDataFile(
118 const base::FilePath& path) { 115 const base::FilePath& path) {
119 VLOG(1) << "Setting CLD data file location: " << path.value(); 116 VLOG(1) << "Setting CLD data file location: " << path.value();
120 base::AutoLock lock(cld_file_lock.Get()); 117 translate::DataFileBrowserCldDataProvider::SetCldDataFilePath(path);
121 cld_file.Get() = path;
122 }
123
124 base::FilePath GetLatestCldDataFile() {
125 base::AutoLock lock(cld_file_lock.Get());
126 // cld_file is an empty path by default, meaning "file not available yet".
127 return cld_file.Get();
128 } 118 }
129 119
130 } // namespace component_updater 120 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698