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

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: Takashi's comments and virtual destructors Created 6 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 | 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 "base/platform_file.h" 16 #include "base/platform_file.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/common/chrome_constants.h"
19 #include "chrome/common/chrome_paths.h" 18 #include "chrome/common/chrome_paths.h"
19 #include "components/translate/content/browser/data_file_browser_cld_data_provid er.h"
20 #include "content/public/browser/browser_thread.h" 20 #include "content/public/browser/browser_thread.h"
21 #include "net/ssl/ssl_config_service.h" 21 #include "net/ssl/ssl_config_service.h"
22 22
23 using component_updater::ComponentUpdateService; 23 using component_updater::ComponentUpdateService;
24 using content::BrowserThread; 24 using content::BrowserThread;
25 25
26 namespace { 26 namespace {
27 27
28 // Once we have acquired a valid file from the component installer, we need to 28 // Once we have acquired a valid file from the component installer, we need to
29 // make the path available to other parts of the system such as the 29 // make the path available to other parts of the system such as the
30 // translation libraries. We create a global to hold onto the path, and a 30 // translation libraries. We create a global to hold onto the path, and a
31 // lock to guard it. See GetLatestCldDataFile(...) for more info. 31 // lock to guard it. See GetLatestCldDataFile(...) for more info.
32 base::LazyInstance<base::Lock> cld_file_lock = LAZY_INSTANCE_INITIALIZER; 32 base::LazyInstance<base::Lock> cld_file_lock = LAZY_INSTANCE_INITIALIZER;
33 base::LazyInstance<base::FilePath> cld_file = LAZY_INSTANCE_INITIALIZER; 33 base::LazyInstance<base::FilePath> cld_file = LAZY_INSTANCE_INITIALIZER;
34 const base::FilePath::CharType kCLDDataFilename[] =
35 FILE_PATH_LITERAL("cld2_data.bin");
34 36
35 } 37 } // namespace
36 38
37 namespace component_updater { 39 namespace component_updater {
38 40
39 // The SHA256 of the SubjectPublicKeyInfo used to sign the extension. 41 // The SHA256 of the SubjectPublicKeyInfo used to sign the extension.
40 // The extension id is: dpedmmgabcgnikllifiidmijgoiihfgf 42 // The extension id is: dpedmmgabcgnikllifiidmijgoiihfgf
41 const uint8 kPublicKeySHA256[32] = { 43 const uint8 kPublicKeySHA256[32] = {
42 0x3f, 0x43, 0xcc, 0x60, 0x12, 0x6d, 0x8a, 0xbb, 44 0x3f, 0x43, 0xcc, 0x60, 0x12, 0x6d, 0x8a, 0xbb,
43 0x85, 0x88, 0x3c, 0x89, 0x6e, 0x88, 0x75, 0x65, 45 0x85, 0x88, 0x3c, 0x89, 0x6e, 0x88, 0x75, 0x65,
44 0xb9, 0x46, 0x09, 0xe8, 0xca, 0x92, 0xdd, 0x82, 46 0xb9, 0x46, 0x09, 0xe8, 0xca, 0x92, 0xdd, 0x82,
45 0x4e, 0x6d, 0x0e, 0xe6, 0x79, 0x8a, 0x87, 0xf5 47 0x4e, 0x6d, 0x0e, 0xe6, 0x79, 0x8a, 0x87, 0xf5
(...skipping 14 matching lines...) Expand all
60 return true; // Nothing custom here. 62 return true; // Nothing custom here.
61 } 63 }
62 64
63 base::FilePath CldComponentInstallerTraits::GetInstalledPath( 65 base::FilePath CldComponentInstallerTraits::GetInstalledPath(
64 const base::FilePath& base) { 66 const base::FilePath& base) {
65 // Currently, all platforms have the file at the same location because there 67 // Currently, all platforms have the file at the same location because there
66 // is no binary difference in the generated file on any supported platform. 68 // is no binary difference in the generated file on any supported platform.
67 // NB: This may change when 64-bit is officially supported. 69 // NB: This may change when 64-bit is officially supported.
68 return base.Append(FILE_PATH_LITERAL("_platform_specific")) 70 return base.Append(FILE_PATH_LITERAL("_platform_specific"))
69 .Append(FILE_PATH_LITERAL("all")) 71 .Append(FILE_PATH_LITERAL("all"))
70 .Append(chrome::kCLDDataFilename); 72 .Append(kCLDDataFilename);
71 } 73 }
72 74
73 void CldComponentInstallerTraits::ComponentReady( 75 void CldComponentInstallerTraits::ComponentReady(
74 const base::Version& version, 76 const base::Version& version,
75 const base::FilePath& path, 77 const base::FilePath& path,
76 scoped_ptr<base::DictionaryValue> manifest) { 78 scoped_ptr<base::DictionaryValue> manifest) {
77 VLOG(1) << "Component ready, version " << version.GetString() << " in " 79 VLOG(1) << "Component ready, version " << version.GetString() << " in "
78 << path.value(); 80 << path.value();
79 SetLatestCldDataFile(GetInstalledPath(path)); 81 SetLatestCldDataFile(GetInstalledPath(path));
80 } 82 }
(...skipping 30 matching lines...) Expand all
111 new CldComponentInstallerTraits()); 113 new CldComponentInstallerTraits());
112 // |cus| will take ownership of |installer| during installer->Register(cus). 114 // |cus| will take ownership of |installer| during installer->Register(cus).
113 DefaultComponentInstaller* installer = 115 DefaultComponentInstaller* installer =
114 new DefaultComponentInstaller(traits.Pass()); 116 new DefaultComponentInstaller(traits.Pass());
115 installer->Register(cus); 117 installer->Register(cus);
116 } 118 }
117 119
118 void CldComponentInstallerTraits::SetLatestCldDataFile( 120 void CldComponentInstallerTraits::SetLatestCldDataFile(
119 const base::FilePath& path) { 121 const base::FilePath& path) {
120 VLOG(1) << "Setting CLD data file location: " << path.value(); 122 VLOG(1) << "Setting CLD data file location: " << path.value();
121 base::AutoLock lock(cld_file_lock.Get()); 123 {
122 cld_file.Get() = path; 124 base::AutoLock lock(cld_file_lock.Get());
125 cld_file.Get() = path;
126 }
127 content::SetCldDataFilePath(path);
123 } 128 }
124 129
125 base::FilePath GetLatestCldDataFile() { 130 base::FilePath GetLatestCldDataFile() {
126 base::AutoLock lock(cld_file_lock.Get()); 131 base::AutoLock lock(cld_file_lock.Get());
127 // cld_file is an empty path by default, meaning "file not available yet". 132 // cld_file is an empty path by default, meaning "file not available yet".
128 return cld_file.Get(); 133 return cld_file.Get();
129 } 134 }
130 135
131 } // namespace component_updater 136 } // namespace component_updater
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698