Chromium Code Reviews| Index: chrome/browser/chromeos/customization_document.h |
| diff --git a/chrome/browser/chromeos/customization_document.h b/chrome/browser/chromeos/customization_document.h |
| index 91970c604b24a23f9f04603bf832b26550eaeb9c..866c254393bd6fc98da48fa4138ee7a2ad6c4bac 100644 |
| --- a/chrome/browser/chromeos/customization_document.h |
| +++ b/chrome/browser/chromeos/customization_document.h |
| @@ -9,11 +9,17 @@ |
| #include <string> |
| #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.
|
| +#include "base/gtest_prod_util.h" |
| #include "base/memory/scoped_ptr.h" |
| +#include "base/memory/singleton.h" |
| +#include "base/timer.h" |
| #include "base/values.h" |
| +#include "chrome/common/net/url_fetcher.h" |
| +#include "googleurl/src/gurl.h" |
| class DictionaryValue; |
| class ListValue; |
| +class PrefService; |
| namespace chromeos { |
| @@ -22,13 +28,17 @@ class SystemAccess; |
| // Base class for OEM customization document classes. |
| class CustomizationDocument { |
| public: |
| - CustomizationDocument() {} |
| virtual ~CustomizationDocument() {} |
| + // 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.
|
| + bool IsReady() const { return root_.get(); } |
| + |
| + protected: |
| + CustomizationDocument() {} |
| + |
| virtual bool LoadManifestFromFile(const FilePath& manifest_path); |
| virtual bool LoadManifestFromString(const std::string& manifest); |
| - protected: |
| std::string GetLocaleSpecificString(const std::string& locale, |
| const std::string& dictionary_name, |
| const std::string& entry_name) const; |
| @@ -42,9 +52,7 @@ class CustomizationDocument { |
| // OEM startup customization document class. |
| 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.
|
| public: |
| - explicit StartupCustomizationDocument(SystemAccess* system_access); |
| - |
| - virtual bool LoadManifestFromString(const std::string& manifest); |
| + static StartupCustomizationDocument* GetInstance(); |
| const std::string& initial_locale() const { return initial_locale_; } |
| const std::string& initial_timezone() const { return initial_timezone_; } |
| @@ -55,11 +63,23 @@ class StartupCustomizationDocument : public CustomizationDocument { |
| std::string GetEULAPage(const std::string& locale) const; |
| private: |
| + FRIEND_TEST(StartupCustomizationDocumentTest, Basic); |
| + FRIEND_TEST(StartupCustomizationDocumentTest, VPD); |
| + FRIEND_TEST(StartupCustomizationDocumentTest, BadManifest); |
| + friend struct DefaultSingletonTraits<StartupCustomizationDocument>; |
| + |
| + // C-tor for singleton construction. |
| + StartupCustomizationDocument(); |
| + |
| + // C-tor for test construction. |
| + StartupCustomizationDocument(SystemAccess* system_access, |
| + const std::string& manifest); |
| + |
| + void Init(SystemAccess* system_access); |
| + |
| // If |attr| exists in machine stat, assign it to |value|. |
| void InitFromMachineStatistic(const char* attr, std::string* value); |
| - SystemAccess* system_access_; |
| - |
| std::string initial_locale_; |
| std::string initial_timezone_; |
| std::string keyboard_layout_; |
| @@ -69,14 +89,68 @@ class StartupCustomizationDocument : public CustomizationDocument { |
| }; |
| // OEM services customization document class. |
| -class ServicesCustomizationDocument : public CustomizationDocument { |
| +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.
|
| + private URLFetcher::Delegate { |
| public: |
| - ServicesCustomizationDocument() {} |
| + static ServicesCustomizationDocument* GetInstance(); |
| + |
| + // Registers preferences. |
| + static void RegisterPrefs(PrefService* local_state); |
| + |
| + // Return true if the customization was applied. Customization is applied only |
| + // once per machine. |
| + 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
|
| + |
| + // Start fetching customization document. |
| + void StartFetching(); |
| + |
| + // Apply customization and save in machine options that customization was |
| + // applied successfully. Return true if customization was applied. |
| + bool ApplyCustmization(); |
|
Nikita (slow)
2011/04/27 13:57:07
nit: Customization.
Dmitry Polukhin
2011/04/27 14:56:15
Done.
|
| std::string GetInitialStartPage(const std::string& locale) const; |
| std::string GetSupportPage(const std::string& locale) const; |
| private: |
| + FRIEND_TEST(ServicesCustomizationDocumentTest, Basic); |
| + FRIEND_TEST(ServicesCustomizationDocumentTest, BadManifest); |
| + friend struct DefaultSingletonTraits<ServicesCustomizationDocument>; |
| + |
| + // C-tor for singleton construction. |
| + ServicesCustomizationDocument(); |
| + |
| + // C-tor for test construction. |
| + explicit ServicesCustomizationDocument(const std::string& manifest); |
| + |
| + // Save applied state in machine settings. |
| + static void SetApplied(bool val); |
| + |
| + // Overriden from URLFetcher::Delegate: |
| + virtual void OnURLFetchComplete(const URLFetcher* source, |
| + const GURL& url, |
| + const net::URLRequestStatus& status, |
| + int response_code, |
| + const ResponseCookies& cookies, |
| + const std::string& data); |
| + |
| + // Initiate file fetching. |
| + void StartFileFetch(); |
| + |
| + // Executes on FILE thread and reads file to string. |
| + void ReadFileInBackground(const FilePath& file); |
| + |
| + // Services customization manifest URL. |
| + GURL url_; |
| + |
| + // URLFetcher instance. |
| + scoped_ptr<URLFetcher> url_fetcher_; |
| + |
| + // Timer to retry fetching file if network is not available. |
| + base::OneShotTimer<ServicesCustomizationDocument> retry_timer_; |
| + |
| + // How many times we already tried to fetch customization manifest file. |
| + int num_retries_; |
| + |
| DISALLOW_COPY_AND_ASSIGN(ServicesCustomizationDocument); |
| }; |