1d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Copyright (c) 2013 The Chromium Authors. All rights reserved. 2d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Use of this source code is governed by a BSD-style license that can be 3d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// found in the LICENSE file. 4d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 5d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#ifndef CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_ 6d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#define CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_ 7d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 85d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <string> 95d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <utility> 105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include <vector> 115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 12d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#include "base/basictypes.h" 135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/memory/scoped_ptr.h" 145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "base/memory/weak_ptr.h" 151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "base/strings/string_split.h" 16d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#include "chrome/browser/prefs/session_startup_pref.h" 175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/profile_resetter/profile_resetter.h" 18d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 19d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)namespace base { 20d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class ListValue; 21d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 22d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 23d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// ResettableSettingsSnapshot captures some settings values at constructor. It 24d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// can calculate the difference between two snapshots. That is, modified fields. 25d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass ResettableSettingsSnapshot { 26d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch public: 27d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // ExtensionList is a vector of pairs. The first component is the extension 28d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // id, the second is the name. 291320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci typedef base::StringPairs ExtensionList; 30d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch // All types of settings handled by this class. 31d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch enum Field { 324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) STARTUP_MODE = 1 << 0, 334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) HOMEPAGE = 1 << 1, 344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) DSE_URL = 1 << 2, 354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXTENSIONS = 1 << 3, 365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) SHORTCUTS = 1 << 4, 374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) ALL_FIELDS = STARTUP_MODE | HOMEPAGE | DSE_URL | EXTENSIONS | SHORTCUTS, 39d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch }; 40d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 41d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch explicit ResettableSettingsSnapshot(Profile* profile); 42d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch ~ResettableSettingsSnapshot(); 43d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 44d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch // Getters. 45d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const std::vector<GURL>& startup_urls() const { return startup_.urls; } 46d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 47d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch SessionStartupPref::Type startup_type() const { return startup_.type; } 48d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 49d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const std::string& homepage() const { return homepage_; } 50d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 51d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch bool homepage_is_ntp() const { return homepage_is_ntp_; } 52d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 536e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) bool show_home_button() const { return show_home_button_; } 546e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) 55d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const std::string& dse_url() const { return dse_url_; } 56d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 57d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const ExtensionList& enabled_extensions() const { 58ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch return enabled_extensions_; 59ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch } 60ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 615d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::vector<ShortcutCommand>& shortcuts() const { 625d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return shortcuts_; 635d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 645d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 655d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool shortcuts_determined() const { 665d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) return shortcuts_determined_; 675d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) } 685d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 69ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // Substitutes |enabled_extensions_| with 70ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // |enabled_extensions_|\|snapshot.enabled_extensions_|. 71ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch void Subtract(const ResettableSettingsSnapshot& snapshot); 72d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 73d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch // For each member 'm' compares |this->m| with |snapshot.m| and sets the 74d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch // corresponding |ResetableSettingsSnapshot::Field| bit to 1 in case of 75d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch // difference. 76d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch // The return value is a bit mask of Field values signifying which members 77d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch // were different. 78d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch int FindDifferentFields(const ResettableSettingsSnapshot& snapshot) const; 79d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Collects the shortcuts asynchronously and calls |callback|. If the request 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // has been made already, noop. 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void RequestShortcuts(const base::Closure& callback); 835d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 84d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch private: 855d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Fills the |shortcuts_| member and calls |callback|. 865d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void SetShortcutsAndReport( 875d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const base::Closure& callback, 885d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const std::vector<ShortcutCommand>& shortcuts); 895d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 90d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch // Startup pages. URLs are always stored sorted. 91d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch SessionStartupPref startup_; 92d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 93d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch std::string homepage_; 94d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch bool homepage_is_ntp_; 956e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles) bool show_home_button_; 96d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 97d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch // Default search engine. 98d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch std::string dse_url_; 99d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 100d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // List of pairs [id, name] for enabled extensions. Always sorted. 101d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ExtensionList enabled_extensions_; 102ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 1035d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Chrome shortcuts (e.g. icons on the Windows desktop, etc.) with non-empty 1045d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // arguments. 1055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::vector<ShortcutCommand> shortcuts_; 1065d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1075d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // |shortcuts_| were retrieved. 1085d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) bool shortcuts_determined_; 1095d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1105d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The flag to cancel shortcuts retrieving. 1115d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) scoped_refptr<SharedCancellationFlag> cancellation_flag_; 1125d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 1135d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) base::WeakPtrFactory<ResettableSettingsSnapshot> weak_ptr_factory_; 1145d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 115d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch DISALLOW_COPY_AND_ASSIGN(ResettableSettingsSnapshot); 116d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch}; 117d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 1181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// The caller of ResettableSettingsSnapshot. 1191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tuccienum SnapshotCaller { 1201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci PROFILE_RESET_WEBUI = 0, 1211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci PROFILE_RESET_PROMPT, 1221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci}; 1231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 124d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Serializes specified |snapshot| members to JSON format. |field_mask| is a bit 125d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// mask of ResettableSettingsSnapshot::Field values. 126d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochstd::string SerializeSettingsReport(const ResettableSettingsSnapshot& snapshot, 1270f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) int field_mask); 128d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 129d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Sends |report| as a feedback. |report| is supposed to be result of 130d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// SerializeSettingsReport(). 1310f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)void SendSettingsFeedback(const std::string& report, 1321320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci Profile* profile, 1331320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci SnapshotCaller caller); 134d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 1355d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Returns list of key/value pairs for all available reported information 1365d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// from the |profile| and some additional fields. 1375d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)scoped_ptr<base::ListValue> GetReadableFeedbackForSnapshot( 1385d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) Profile* profile, 1395d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) const ResettableSettingsSnapshot& snapshot); 140d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 141d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#endif // CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_ 142