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

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

Issue 6893052: Make customization documents singletons. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments resolved Created 9 years, 8 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
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 parsed.
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.
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).
43 class StartupCustomizationDocument : public CustomizationDocument { 56 class StartupCustomizationDocument : public CustomizationDocument {
44 public: 57 public:
45 explicit StartupCustomizationDocument(SystemAccess* system_access); 58 static StartupCustomizationDocument* GetInstance();
46
47 virtual bool LoadManifestFromString(const std::string& manifest);
48 59
49 const std::string& initial_locale() const { return initial_locale_; } 60 const std::string& initial_locale() const { return initial_locale_; }
50 const std::string& initial_timezone() const { return initial_timezone_; } 61 const std::string& initial_timezone() const { return initial_timezone_; }
51 const std::string& keyboard_layout() const { return keyboard_layout_; } 62 const std::string& keyboard_layout() const { return keyboard_layout_; }
52 const std::string& registration_url() const { return registration_url_; } 63 const std::string& registration_url() const { return registration_url_; }
53 64
54 std::string GetHelpPage(const std::string& locale) const; 65 std::string GetHelpPage(const std::string& locale) const;
55 std::string GetEULAPage(const std::string& locale) const; 66 std::string GetEULAPage(const std::string& locale) const;
56 67
57 private: 68 private:
69 FRIEND_TEST(StartupCustomizationDocumentTest, Basic);
70 FRIEND_TEST(StartupCustomizationDocumentTest, VPD);
71 FRIEND_TEST(StartupCustomizationDocumentTest, BadManifest);
72 friend struct DefaultSingletonTraits<StartupCustomizationDocument>;
73
74 // C-tor for singleton construction.
75 StartupCustomizationDocument();
76
77 // C-tor for test construction.
78 StartupCustomizationDocument(SystemAccess* system_access,
79 const std::string& manifest);
80
81 void Init(SystemAccess* system_access);
82
58 // If |attr| exists in machine stat, assign it to |value|. 83 // If |attr| exists in machine stat, assign it to |value|.
59 void InitFromMachineStatistic(const char* attr, std::string* value); 84 void InitFromMachineStatistic(const char* attr, std::string* value);
60 85
61 SystemAccess* system_access_;
62
63 std::string initial_locale_; 86 std::string initial_locale_;
64 std::string initial_timezone_; 87 std::string initial_timezone_;
65 std::string keyboard_layout_; 88 std::string keyboard_layout_;
66 std::string registration_url_; 89 std::string registration_url_;
67 90
68 DISALLOW_COPY_AND_ASSIGN(StartupCustomizationDocument); 91 DISALLOW_COPY_AND_ASSIGN(StartupCustomizationDocument);
69 }; 92 };
70 93
71 // OEM services customization document class. 94 // OEM services customization document class.
72 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 {
73 public: 101 public:
74 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();
75 117
76 std::string GetInitialStartPage(const std::string& locale) const; 118 std::string GetInitialStartPage(const std::string& locale) const;
77 std::string GetSupportPage(const std::string& locale) const; 119 std::string GetSupportPage(const std::string& locale) const;
78 120
79 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
80 DISALLOW_COPY_AND_ASSIGN(ServicesCustomizationDocument); 161 DISALLOW_COPY_AND_ASSIGN(ServicesCustomizationDocument);
81 }; 162 };
82 163
83 } // namespace chromeos 164 } // namespace chromeos
84 165
85 #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