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

Side by Side Diff: chrome/browser/chromeos/customization_document.h

Issue 6902107: Merge 82987, 83304 - make sure that OEM tab is shown even if first login is Guest (Closed) Base URL: svn://svn.chromium.org/chrome/branches/742/src/
Patch Set: Created 9 years, 7 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
« no previous file with comments | « no previous file | chrome/browser/chromeos/customization_document.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #ifndef CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ 5 #ifndef CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_
6 #define CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ 6 #define CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 10
11 #include "base/file_path.h" 11 #include "base/gtest_prod_util.h"
12 #include "base/memory/scoped_ptr.h" 12 #include "base/memory/scoped_ptr.h"
13 #include "base/memory/singleton.h"
14 #include "base/timer.h"
13 #include "base/values.h" 15 #include "base/values.h"
16 #include "chrome/common/net/url_fetcher.h"
17 #include "googleurl/src/gurl.h"
14 18
15 class DictionaryValue; 19 class DictionaryValue;
20 class FilePath;
16 class ListValue; 21 class ListValue;
22 class PrefService;
17 23
18 namespace chromeos { 24 namespace chromeos {
19 25
26 class SystemAccess;
27
20 // Base class for OEM customization document classes. 28 // Base class for OEM customization document classes.
21 class CustomizationDocument { 29 class CustomizationDocument {
22 public: 30 public:
31 virtual ~CustomizationDocument() {}
32
33 // Return true if the document was successfully fetched and parsed.
34 bool IsReady() const { return root_.get(); }
35
36 protected:
23 CustomizationDocument() {} 37 CustomizationDocument() {}
24 virtual ~CustomizationDocument() {}
25 38
26 virtual bool LoadManifestFromFile(const FilePath& manifest_path); 39 virtual bool LoadManifestFromFile(const FilePath& manifest_path);
27 virtual bool LoadManifestFromString(const std::string& manifest); 40 virtual bool LoadManifestFromString(const std::string& manifest);
28 41
29 protected:
30 std::string GetLocaleSpecificString(const std::string& locale, 42 std::string GetLocaleSpecificString(const std::string& locale,
31 const std::string& dictionary_name, 43 const std::string& dictionary_name,
32 const std::string& entry_name) const; 44 const std::string& entry_name) const;
33 45
34 scoped_ptr<DictionaryValue> root_; 46 scoped_ptr<DictionaryValue> root_;
35 47
36 private: 48 private:
37 DISALLOW_COPY_AND_ASSIGN(CustomizationDocument); 49 DISALLOW_COPY_AND_ASSIGN(CustomizationDocument);
38 }; 50 };
39 51
40 // OEM startup customization document class. 52 // OEM startup customization document class.
53 // Now StartupCustomizationDocument is loaded in c-tor so just after create it
54 // may be ready or not (if manifest is missing or corrupted) and this state
55 // won't be changed later (i.e. IsReady() always return the same value).
41 class StartupCustomizationDocument : public CustomizationDocument { 56 class StartupCustomizationDocument : public CustomizationDocument {
42 public: 57 public:
43 StartupCustomizationDocument() {} 58 static StartupCustomizationDocument* GetInstance();
44
45 virtual bool LoadManifestFromString(const std::string& manifest);
46 59
47 const std::string& initial_locale() const { return initial_locale_; } 60 const std::string& initial_locale() const { return initial_locale_; }
48 const std::string& initial_timezone() const { return initial_timezone_; } 61 const std::string& initial_timezone() const { return initial_timezone_; }
49 const std::string& keyboard_layout() const { return keyboard_layout_; } 62 const std::string& keyboard_layout() const { return keyboard_layout_; }
50 const std::string& registration_url() const { return registration_url_; } 63 const std::string& registration_url() const { return registration_url_; }
51 64
52 std::string GetHelpPage(const std::string& locale) const; 65 std::string GetHelpPage(const std::string& locale) const;
53 std::string GetEULAPage(const std::string& locale) const; 66 std::string GetEULAPage(const std::string& locale) const;
54 67
55 // Returns HWID for the machine. Declared as virtual to override in tests. 68 private:
56 virtual std::string GetHWID() const; 69 FRIEND_TEST(StartupCustomizationDocumentTest, Basic);
70 FRIEND_TEST(StartupCustomizationDocumentTest, VPD);
71 FRIEND_TEST(StartupCustomizationDocumentTest, BadManifest);
72 friend struct DefaultSingletonTraits<StartupCustomizationDocument>;
57 73
58 private: 74 // C-tor for singleton construction.
59 typedef std::map<std::string, std::string> VPDMap; 75 StartupCustomizationDocument();
60 76
61 // Returns VPD as string. Declared as virtual to override in tests. 77 // C-tor for test construction.
62 virtual std::string GetVPD() const; 78 StartupCustomizationDocument(SystemAccess* system_access,
79 const std::string& manifest);
63 80
64 // Parse VPD file as string and initialize |vpd_map|. 81 void Init(SystemAccess* system_access);
65 bool ParseVPD(const std::string& vpd_string, VPDMap* vpd_map);
66 82
67 // If |attr| exists in |vpd_map|, assign it value to |value|; 83 // If |attr| exists in machine stat, assign it to |value|.
68 void InitFromVPD(const VPDMap& vpd_map, const char* attr, std::string* value); 84 void InitFromMachineStatistic(const char* attr, std::string* value);
69 85
70 std::string initial_locale_; 86 std::string initial_locale_;
71 std::string initial_timezone_; 87 std::string initial_timezone_;
72 std::string keyboard_layout_; 88 std::string keyboard_layout_;
73 std::string registration_url_; 89 std::string registration_url_;
74 90
75 DISALLOW_COPY_AND_ASSIGN(StartupCustomizationDocument); 91 DISALLOW_COPY_AND_ASSIGN(StartupCustomizationDocument);
76 }; 92 };
77 93
78 // OEM services customization document class. 94 // OEM services customization document class.
79 class ServicesCustomizationDocument : public CustomizationDocument { 95 // ServicesCustomizationDocument is fetched from network or local file but on
96 // FILE thread therefore it may not be ready just after creation. Fetching of
97 // the manifest should be initiated outside this class by calling
98 // StartFetching() method. User of the file should check IsReady before use it.
99 class ServicesCustomizationDocument : public CustomizationDocument,
100 private URLFetcher::Delegate {
80 public: 101 public:
81 ServicesCustomizationDocument() {} 102 static ServicesCustomizationDocument* GetInstance();
103
104 // Registers preferences.
105 static void RegisterPrefs(PrefService* local_state);
106
107 // Return true if the customization was applied. Customization is applied only
108 // once per machine.
109 static bool WasApplied();
110
111 // Start fetching customization document.
112 void StartFetching();
113
114 // Apply customization and save in machine options that customization was
115 // applied successfully. Return true if customization was applied.
116 bool ApplyCustomization();
82 117
83 std::string GetInitialStartPage(const std::string& locale) const; 118 std::string GetInitialStartPage(const std::string& locale) const;
84 std::string GetSupportPage(const std::string& locale) const; 119 std::string GetSupportPage(const std::string& locale) const;
85 120
86 private: 121 private:
122 FRIEND_TEST(ServicesCustomizationDocumentTest, Basic);
123 FRIEND_TEST(ServicesCustomizationDocumentTest, BadManifest);
124 friend struct DefaultSingletonTraits<ServicesCustomizationDocument>;
125
126 // C-tor for singleton construction.
127 ServicesCustomizationDocument();
128
129 // C-tor for test construction.
130 explicit ServicesCustomizationDocument(const std::string& manifest);
131
132 // Save applied state in machine settings.
133 static void SetApplied(bool val);
134
135 // Overriden from URLFetcher::Delegate:
136 virtual void OnURLFetchComplete(const URLFetcher* source,
137 const GURL& url,
138 const net::URLRequestStatus& status,
139 int response_code,
140 const ResponseCookies& cookies,
141 const std::string& data);
142
143 // Initiate file fetching.
144 void StartFileFetch();
145
146 // Executes on FILE thread and reads file to string.
147 void ReadFileInBackground(const FilePath& file);
148
149 // Services customization manifest URL.
150 GURL url_;
151
152 // URLFetcher instance.
153 scoped_ptr<URLFetcher> url_fetcher_;
154
155 // Timer to retry fetching file if network is not available.
156 base::OneShotTimer<ServicesCustomizationDocument> retry_timer_;
157
158 // How many times we already tried to fetch customization manifest file.
159 int num_retries_;
160
87 DISALLOW_COPY_AND_ASSIGN(ServicesCustomizationDocument); 161 DISALLOW_COPY_AND_ASSIGN(ServicesCustomizationDocument);
88 }; 162 };
89 163
90 } // namespace chromeos 164 } // namespace chromeos
91 165
92 #endif // CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ 166 #endif // CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/chromeos/customization_document.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698