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 8d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#include "base/basictypes.h" 9d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#include "chrome/browser/prefs/session_startup_pref.h" 10d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 11d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)namespace base { 12d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)class ListValue; 13d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)} 14d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 15d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// ResettableSettingsSnapshot captures some settings values at constructor. It 16d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// can calculate the difference between two snapshots. That is, modified fields. 17d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochclass ResettableSettingsSnapshot { 18d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch public: 19d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // ExtensionList is a vector of pairs. The first component is the extension 20d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // id, the second is the name. 21d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) typedef std::vector<std::pair<std::string, std::string> > ExtensionList; 22d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch // All types of settings handled by this class. 23d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch enum Field { 244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) STARTUP_MODE = 1 << 0, 254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) HOMEPAGE = 1 << 1, 264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) DSE_URL = 1 << 2, 274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) EXTENSIONS = 1 << 3, 284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) ALL_FIELDS = STARTUP_MODE | HOMEPAGE | DSE_URL | EXTENSIONS, 30d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch }; 31d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 32d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch explicit ResettableSettingsSnapshot(Profile* profile); 33d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch ~ResettableSettingsSnapshot(); 34d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 35d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch // Getters. 36d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const std::vector<GURL>& startup_urls() const { return startup_.urls; } 37d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 38d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch SessionStartupPref::Type startup_type() const { return startup_.type; } 39d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 40d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const std::string& homepage() const { return homepage_; } 41d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 42d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch bool homepage_is_ntp() const { return homepage_is_ntp_; } 43d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 44d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch const std::string& dse_url() const { return dse_url_; } 45d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 46d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) const ExtensionList& enabled_extensions() const { 47ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch return enabled_extensions_; 48ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch } 49ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 50ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // Substitutes |enabled_extensions_| with 51ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // |enabled_extensions_|\|snapshot.enabled_extensions_|. 52ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch void Subtract(const ResettableSettingsSnapshot& snapshot); 53d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 54d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch // For each member 'm' compares |this->m| with |snapshot.m| and sets the 55d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch // corresponding |ResetableSettingsSnapshot::Field| bit to 1 in case of 56d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch // difference. 57d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch // The return value is a bit mask of Field values signifying which members 58d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch // were different. 59d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch int FindDifferentFields(const ResettableSettingsSnapshot& snapshot) const; 60d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 61d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch private: 62d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch // Startup pages. URLs are always stored sorted. 63d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch SessionStartupPref startup_; 64d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 65d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch std::string homepage_; 66d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch bool homepage_is_ntp_; 67d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 68d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch // Default search engine. 69d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch std::string dse_url_; 70d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 71d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // List of pairs [id, name] for enabled extensions. Always sorted. 72d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) ExtensionList enabled_extensions_; 73ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch 74d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch DISALLOW_COPY_AND_ASSIGN(ResettableSettingsSnapshot); 75d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch}; 76d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 770f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)// The caller of ResettableSettingsSnapshot. 784e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)enum SnapshotCaller { 794e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) PROFILE_RESET_WEBUI = 0, 800f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) PROFILE_RESET_PROMPT, 814e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}; 824e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 83d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Serializes specified |snapshot| members to JSON format. |field_mask| is a bit 84d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// mask of ResettableSettingsSnapshot::Field values. 85d3868032626d59662ff73b372b5d584c1d144c53Ben Murdochstd::string SerializeSettingsReport(const ResettableSettingsSnapshot& snapshot, 860f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) int field_mask); 87d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 88d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// Sends |report| as a feedback. |report| is supposed to be result of 89d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch// SerializeSettingsReport(). 900f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles)void SendSettingsFeedback(const std::string& report, 910f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) Profile* profile, 920f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) SnapshotCaller caller); 93d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch 94d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// Returns list of key/value pairs for all reported information from the 95d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)// |profile| and some additional fields. 96d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles)base::ListValue* GetReadableFeedback(Profile* profile); 97d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 98d3868032626d59662ff73b372b5d584c1d144c53Ben Murdoch#endif // CHROME_BROWSER_PROFILE_RESETTER_RESETTABLE_SETTINGS_SNAPSHOT_H_ 99