Upstream version 9.38.198.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / profile_resetter / resettable_settings_snapshot.h
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_
6 #define CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_
7
8 #include <string>
9 #include <utility>
10 #include <vector>
11
12 #include "base/basictypes.h"
13 #include "base/memory/scoped_ptr.h"
14 #include "base/memory/weak_ptr.h"
15 #include "chrome/browser/prefs/session_startup_pref.h"
16 #include "chrome/browser/profile_resetter/profile_resetter.h"
17
18 namespace base {
19 class ListValue;
20 }
21
22 // ResettableSettingsSnapshot captures some settings values at constructor. It
23 // can calculate the difference between two snapshots. That is, modified fields.
24 class ResettableSettingsSnapshot {
25  public:
26   // ExtensionList is a vector of pairs. The first component is the extension
27   // id, the second is the name.
28   typedef std::vector<std::pair<std::string, std::string> > ExtensionList;
29   // All types of settings handled by this class.
30   enum Field {
31     STARTUP_MODE = 1 << 0,
32     HOMEPAGE = 1 << 1,
33     DSE_URL = 1 << 2,
34     EXTENSIONS = 1 << 3,
35     SHORTCUTS = 1 << 4,
36
37     ALL_FIELDS = STARTUP_MODE | HOMEPAGE | DSE_URL | EXTENSIONS | SHORTCUTS,
38   };
39
40   explicit ResettableSettingsSnapshot(Profile* profile);
41   ~ResettableSettingsSnapshot();
42
43   // Getters.
44   const std::vector<GURL>& startup_urls() const { return startup_.urls; }
45
46   SessionStartupPref::Type startup_type() const { return startup_.type; }
47
48   const std::string& homepage() const { return homepage_; }
49
50   bool homepage_is_ntp() const { return homepage_is_ntp_; }
51
52   bool show_home_button() const { return show_home_button_; }
53
54   const std::string& dse_url() const { return dse_url_; }
55
56   const ExtensionList& enabled_extensions() const {
57     return enabled_extensions_;
58   }
59
60   const std::vector<ShortcutCommand>& shortcuts() const {
61     return shortcuts_;
62   }
63
64   bool shortcuts_determined() const {
65     return shortcuts_determined_;
66   }
67
68   // Substitutes |enabled_extensions_| with
69   // |enabled_extensions_|\|snapshot.enabled_extensions_|.
70   void Subtract(const ResettableSettingsSnapshot& snapshot);
71
72   // For each member 'm' compares |this->m| with |snapshot.m| and sets the
73   // corresponding |ResetableSettingsSnapshot::Field| bit to 1 in case of
74   // difference.
75   // The return value is a bit mask of Field values signifying which members
76   // were different.
77   int FindDifferentFields(const ResettableSettingsSnapshot& snapshot) const;
78
79   // Collects the shortcuts asynchronously and calls |callback|. If the request
80   // has been made already, noop.
81   void RequestShortcuts(const base::Closure& callback);
82
83  private:
84   // Fills the |shortcuts_| member and calls |callback|.
85   void SetShortcutsAndReport(
86       const base::Closure& callback,
87       const std::vector<ShortcutCommand>& shortcuts);
88
89   // Startup pages. URLs are always stored sorted.
90   SessionStartupPref startup_;
91
92   std::string homepage_;
93   bool homepage_is_ntp_;
94   bool show_home_button_;
95
96   // Default search engine.
97   std::string dse_url_;
98
99   // List of pairs [id, name] for enabled extensions. Always sorted.
100   ExtensionList enabled_extensions_;
101
102   // Chrome shortcuts (e.g. icons on the Windows desktop, etc.) with non-empty
103   // arguments.
104   std::vector<ShortcutCommand> shortcuts_;
105
106   // |shortcuts_| were retrieved.
107   bool shortcuts_determined_;
108
109   // The flag to cancel shortcuts retrieving.
110   scoped_refptr<SharedCancellationFlag> cancellation_flag_;
111
112   base::WeakPtrFactory<ResettableSettingsSnapshot> weak_ptr_factory_;
113
114   DISALLOW_COPY_AND_ASSIGN(ResettableSettingsSnapshot);
115 };
116
117 // Serializes specified |snapshot| members to JSON format. |field_mask| is a bit
118 // mask of ResettableSettingsSnapshot::Field values.
119 std::string SerializeSettingsReport(const ResettableSettingsSnapshot& snapshot,
120                                     int field_mask);
121
122 // Sends |report| as a feedback. |report| is supposed to be result of
123 // SerializeSettingsReport().
124 void SendSettingsFeedback(const std::string& report,
125                           Profile* profile);
126
127 // Returns list of key/value pairs for all available reported information
128 // from the |profile| and some additional fields.
129 scoped_ptr<base::ListValue> GetReadableFeedbackForSnapshot(
130     Profile* profile,
131     const ResettableSettingsSnapshot& snapshot);
132
133 #endif  // CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_