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

Side by Side Diff: chrome/browser/google/google_util.cc

Issue 11412067: [rlz,cros] RLZ glue for ChromeOS. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Compile fix Created 8 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/google/google_util.h" 5 #include "chrome/browser/google/google_util.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/command_line.h" 10 #include "base/command_line.h"
11 #include "base/string16.h" 11 #include "base/string16.h"
12 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/string_split.h" 13 #include "base/string_split.h"
14 #include "base/string_util.h" 14 #include "base/string_util.h"
15 #include "base/utf_string_conversions.h" 15 #include "base/utf_string_conversions.h"
16 #include "chrome/browser/browser_process.h" 16 #include "chrome/browser/browser_process.h"
17 #include "chrome/browser/google/google_url_tracker.h" 17 #include "chrome/browser/google/google_url_tracker.h"
18 #include "chrome/common/chrome_switches.h" 18 #include "chrome/common/chrome_switches.h"
19 #include "chrome/common/net/url_util.h" 19 #include "chrome/common/net/url_util.h"
20 #include "chrome/installer/util/google_update_settings.h" 20 #include "chrome/installer/util/google_update_settings.h"
21 #include "googleurl/src/gurl.h" 21 #include "googleurl/src/gurl.h"
22 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 22 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
23 23
24 #if defined(OS_MACOSX) 24 #if defined(OS_MACOSX)
25 #include "chrome/browser/mac/keystone_glue.h" 25 #include "chrome/browser/mac/keystone_glue.h"
26 #elif defined(OS_CHROMEOS)
27 #include "base/file_util.h"
28 #include "base/lazy_instance.h"
29 #include "base/string_util.h"
30 #include "base/threading/thread_restrictions.h"
26 #endif 31 #endif
27 32
28 #if defined(GOOGLE_CHROME_BUILD) 33 #if defined(GOOGLE_CHROME_BUILD)
29 #include "chrome/browser/google/linkdoctor_internal/linkdoctor_internal.h" 34 #include "chrome/browser/google/linkdoctor_internal/linkdoctor_internal.h"
30 #endif 35 #endif
31 36
32 #ifndef LINKDOCTOR_SERVER_REQUEST_URL 37 #ifndef LINKDOCTOR_SERVER_REQUEST_URL
33 #define LINKDOCTOR_SERVER_REQUEST_URL "" 38 #define LINKDOCTOR_SERVER_REQUEST_URL ""
34 #endif 39 #endif
35 40
(...skipping 12 matching lines...) Expand all
48 itr != parameters.end(); 53 itr != parameters.end();
49 ++itr) { 54 ++itr) {
50 if (StartsWithASCII(*itr, "q=", false) && itr->size() > 2) 55 if (StartsWithASCII(*itr, "q=", false) && itr->size() > 2)
51 return true; 56 return true;
52 } 57 }
53 return false; 58 return false;
54 } 59 }
55 60
56 bool gUseMockLinkDoctorBaseURLForTesting = false; 61 bool gUseMockLinkDoctorBaseURLForTesting = false;
57 62
63 #if defined(OS_CHROMEOS)
64 // Path to file that stores RLZ brand code on ChromeOS.
65 const char kRLZBrandFilePath[] =
66 FILE_PATH_LITERAL("/opt/oem/etc/rlz_brand_code");
67
68 // Simple class for caching brand code, meant to be used as a LazyInstance.
69 class BrandCode {
70 public:
71 BrandCode() {
72 // Need to perform I/O for the first time, same as on Win.
73 base::ThreadRestrictions::ScopedAllowIO allow_io;
74 FilePath brand_file_path(kRLZBrandFilePath);
75 if (!file_util::ReadFileToString(brand_file_path, &brand_))
76 LOG(WARNING) << "Brand code file missing: " << brand_file_path.value();
77 TrimWhitespace(brand_, TRIM_ALL, &brand_);
78 }
79
80 // Brand code, may be empty.
81 const std::string& brand() { return brand_; }
82
83 private:
84 std::string brand_;
85 };
86
87 base::LazyInstance<BrandCode> g_cached_brand = LAZY_INSTANCE_INITIALIZER;
88 #endif
89
58 } // anonymous namespace 90 } // anonymous namespace
59 91
60 namespace google_util { 92 namespace google_util {
61 93
62 GURL LinkDoctorBaseURL() { 94 GURL LinkDoctorBaseURL() {
63 if (gUseMockLinkDoctorBaseURLForTesting) 95 if (gUseMockLinkDoctorBaseURLForTesting)
64 return GURL("http://mock.linkdoctor.url/for?testing"); 96 return GURL("http://mock.linkdoctor.url/for?testing");
65 return GURL(LINKDOCTOR_SERVER_REQUEST_URL); 97 return GURL(LINKDOCTOR_SERVER_REQUEST_URL);
66 } 98 }
67 99
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 #else 165 #else
134 166
135 bool GetBrand(std::string* brand) { 167 bool GetBrand(std::string* brand) {
136 if (brand_for_testing) { 168 if (brand_for_testing) {
137 brand->assign(brand_for_testing); 169 brand->assign(brand_for_testing);
138 return true; 170 return true;
139 } 171 }
140 172
141 #if defined(OS_MACOSX) 173 #if defined(OS_MACOSX)
142 brand->assign(keystone_glue::BrandCode()); 174 brand->assign(keystone_glue::BrandCode());
175 #elif defined(OS_CHROMEOS)
176 brand->assign(g_cached_brand.Get().brand());
143 #else 177 #else
144 brand->clear(); 178 brand->clear();
145 #endif 179 #endif
146 return true; 180 return true;
147 } 181 }
148 182
149 bool GetReactivationBrand(std::string* brand) { 183 bool GetReactivationBrand(std::string* brand) {
150 brand->clear(); 184 brand->clear();
151 return true; 185 return true;
152 } 186 }
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 const char* const kBrands[] = { 350 const char* const kBrands[] = {
317 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE", 351 "CHIQ", "CHSG", "HLJY", "NTMO", "OOBA", "OOBB", "OOBC", "OOBD", "OOBE",
318 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM", 352 "OOBF", "OOBG", "OOBH", "OOBI", "OOBJ", "IDCM",
319 }; 353 };
320 const char* const* end = &kBrands[arraysize(kBrands)]; 354 const char* const* end = &kBrands[arraysize(kBrands)];
321 const char* const* found = std::find(&kBrands[0], end, brand); 355 const char* const* found = std::find(&kBrands[0], end, brand);
322 return found != end; 356 return found != end;
323 } 357 }
324 358
325 } // namespace google_util 359 } // namespace google_util
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698