OLD | NEW |
---|---|
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/file_path.h" |
Nikita (slow)
2011/04/27 13:57:07
Could FilePath be forward declared here?
Dmitry Polukhin
2011/04/27 14:56:15
Done.
| |
12 #include "base/gtest_prod_util.h" | |
12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/memory/singleton.h" | |
15 #include "base/timer.h" | |
13 #include "base/values.h" | 16 #include "base/values.h" |
17 #include "chrome/common/net/url_fetcher.h" | |
18 #include "googleurl/src/gurl.h" | |
14 | 19 |
15 class DictionaryValue; | 20 class DictionaryValue; |
16 class ListValue; | 21 class ListValue; |
22 class PrefService; | |
17 | 23 |
18 namespace chromeos { | 24 namespace chromeos { |
19 | 25 |
20 class SystemAccess; | 26 class SystemAccess; |
21 | 27 |
22 // Base class for OEM customization document classes. | 28 // Base class for OEM customization document classes. |
23 class CustomizationDocument { | 29 class CustomizationDocument { |
24 public: | 30 public: |
31 virtual ~CustomizationDocument() {} | |
32 | |
33 // Return true if the document was successfully fetched and ready for apply. | |
Nikita (slow)
2011/04/27 13:57:07
nit: was successfully fetched and parsed.
Dmitry Polukhin
2011/04/27 14:56:15
Done.
| |
34 bool IsReady() const { return root_.get(); } | |
35 | |
36 protected: | |
25 CustomizationDocument() {} | 37 CustomizationDocument() {} |
26 virtual ~CustomizationDocument() {} | |
27 | 38 |
28 virtual bool LoadManifestFromFile(const FilePath& manifest_path); | 39 virtual bool LoadManifestFromFile(const FilePath& manifest_path); |
29 virtual bool LoadManifestFromString(const std::string& manifest); | 40 virtual bool LoadManifestFromString(const std::string& manifest); |
30 | 41 |
31 protected: | |
32 std::string GetLocaleSpecificString(const std::string& locale, | 42 std::string GetLocaleSpecificString(const std::string& locale, |
33 const std::string& dictionary_name, | 43 const std::string& dictionary_name, |
34 const std::string& entry_name) const; | 44 const std::string& entry_name) const; |
35 | 45 |
36 scoped_ptr<DictionaryValue> root_; | 46 scoped_ptr<DictionaryValue> root_; |
37 | 47 |
38 private: | 48 private: |
39 DISALLOW_COPY_AND_ASSIGN(CustomizationDocument); | 49 DISALLOW_COPY_AND_ASSIGN(CustomizationDocument); |
40 }; | 50 }; |
41 | 51 |
42 // OEM startup customization document class. | 52 // OEM startup customization document class. |
43 class StartupCustomizationDocument : public CustomizationDocument { | 53 class StartupCustomizationDocument : public CustomizationDocument { |
Nikita (slow)
2011/04/27 13:57:07
Please add short comment on life-cycle.
This docum
Dmitry Polukhin
2011/04/27 14:56:15
Done.
| |
44 public: | 54 public: |
45 explicit StartupCustomizationDocument(SystemAccess* system_access); | 55 static StartupCustomizationDocument* GetInstance(); |
46 | |
47 virtual bool LoadManifestFromString(const std::string& manifest); | |
48 | 56 |
49 const std::string& initial_locale() const { return initial_locale_; } | 57 const std::string& initial_locale() const { return initial_locale_; } |
50 const std::string& initial_timezone() const { return initial_timezone_; } | 58 const std::string& initial_timezone() const { return initial_timezone_; } |
51 const std::string& keyboard_layout() const { return keyboard_layout_; } | 59 const std::string& keyboard_layout() const { return keyboard_layout_; } |
52 const std::string& registration_url() const { return registration_url_; } | 60 const std::string& registration_url() const { return registration_url_; } |
53 | 61 |
54 std::string GetHelpPage(const std::string& locale) const; | 62 std::string GetHelpPage(const std::string& locale) const; |
55 std::string GetEULAPage(const std::string& locale) const; | 63 std::string GetEULAPage(const std::string& locale) const; |
56 | 64 |
57 private: | 65 private: |
66 FRIEND_TEST(StartupCustomizationDocumentTest, Basic); | |
67 FRIEND_TEST(StartupCustomizationDocumentTest, VPD); | |
68 FRIEND_TEST(StartupCustomizationDocumentTest, BadManifest); | |
69 friend struct DefaultSingletonTraits<StartupCustomizationDocument>; | |
70 | |
71 // C-tor for singleton construction. | |
72 StartupCustomizationDocument(); | |
73 | |
74 // C-tor for test construction. | |
75 StartupCustomizationDocument(SystemAccess* system_access, | |
76 const std::string& manifest); | |
77 | |
78 void Init(SystemAccess* system_access); | |
79 | |
58 // If |attr| exists in machine stat, assign it to |value|. | 80 // If |attr| exists in machine stat, assign it to |value|. |
59 void InitFromMachineStatistic(const char* attr, std::string* value); | 81 void InitFromMachineStatistic(const char* attr, std::string* value); |
60 | 82 |
61 SystemAccess* system_access_; | |
62 | |
63 std::string initial_locale_; | 83 std::string initial_locale_; |
64 std::string initial_timezone_; | 84 std::string initial_timezone_; |
65 std::string keyboard_layout_; | 85 std::string keyboard_layout_; |
66 std::string registration_url_; | 86 std::string registration_url_; |
67 | 87 |
68 DISALLOW_COPY_AND_ASSIGN(StartupCustomizationDocument); | 88 DISALLOW_COPY_AND_ASSIGN(StartupCustomizationDocument); |
69 }; | 89 }; |
70 | 90 |
71 // OEM services customization document class. | 91 // OEM services customization document class. |
72 class ServicesCustomizationDocument : public CustomizationDocument { | 92 class ServicesCustomizationDocument : public CustomizationDocument, |
Nikita (slow)
2011/04/27 13:57:07
Please add short comment on life-cycle.
This docum
Dmitry Polukhin
2011/04/27 14:56:15
Done.
| |
93 private URLFetcher::Delegate { | |
73 public: | 94 public: |
74 ServicesCustomizationDocument() {} | 95 static ServicesCustomizationDocument* GetInstance(); |
96 | |
97 // Registers preferences. | |
98 static void RegisterPrefs(PrefService* local_state); | |
99 | |
100 // Return true if the customization was applied. Customization is applied only | |
101 // once per machine. | |
102 static bool WasApplied(); | |
Nikita (slow)
2011/04/27 13:57:07
Also expose WasFetched?
Dmitry Polukhin
2011/04/27 14:56:15
Was fetched itself is so interesting. The only int
| |
103 | |
104 // Start fetching customization document. | |
105 void StartFetching(); | |
106 | |
107 // Apply customization and save in machine options that customization was | |
108 // applied successfully. Return true if customization was applied. | |
109 bool ApplyCustmization(); | |
Nikita (slow)
2011/04/27 13:57:07
nit: Customization.
Dmitry Polukhin
2011/04/27 14:56:15
Done.
| |
75 | 110 |
76 std::string GetInitialStartPage(const std::string& locale) const; | 111 std::string GetInitialStartPage(const std::string& locale) const; |
77 std::string GetSupportPage(const std::string& locale) const; | 112 std::string GetSupportPage(const std::string& locale) const; |
78 | 113 |
79 private: | 114 private: |
115 FRIEND_TEST(ServicesCustomizationDocumentTest, Basic); | |
116 FRIEND_TEST(ServicesCustomizationDocumentTest, BadManifest); | |
117 friend struct DefaultSingletonTraits<ServicesCustomizationDocument>; | |
118 | |
119 // C-tor for singleton construction. | |
120 ServicesCustomizationDocument(); | |
121 | |
122 // C-tor for test construction. | |
123 explicit ServicesCustomizationDocument(const std::string& manifest); | |
124 | |
125 // Save applied state in machine settings. | |
126 static void SetApplied(bool val); | |
127 | |
128 // Overriden from URLFetcher::Delegate: | |
129 virtual void OnURLFetchComplete(const URLFetcher* source, | |
130 const GURL& url, | |
131 const net::URLRequestStatus& status, | |
132 int response_code, | |
133 const ResponseCookies& cookies, | |
134 const std::string& data); | |
135 | |
136 // Initiate file fetching. | |
137 void StartFileFetch(); | |
138 | |
139 // Executes on FILE thread and reads file to string. | |
140 void ReadFileInBackground(const FilePath& file); | |
141 | |
142 // Services customization manifest URL. | |
143 GURL url_; | |
144 | |
145 // URLFetcher instance. | |
146 scoped_ptr<URLFetcher> url_fetcher_; | |
147 | |
148 // Timer to retry fetching file if network is not available. | |
149 base::OneShotTimer<ServicesCustomizationDocument> retry_timer_; | |
150 | |
151 // How many times we already tried to fetch customization manifest file. | |
152 int num_retries_; | |
153 | |
80 DISALLOW_COPY_AND_ASSIGN(ServicesCustomizationDocument); | 154 DISALLOW_COPY_AND_ASSIGN(ServicesCustomizationDocument); |
81 }; | 155 }; |
82 | 156 |
83 } // namespace chromeos | 157 } // namespace chromeos |
84 | 158 |
85 #endif // CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ | 159 #endif // CHROME_BROWSER_CHROMEOS_CUSTOMIZATION_DOCUMENT_H_ |
OLD | NEW |