blob: 7d0637d3541ac1c56237897615abe9071cfb1ea8 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_
#define CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_
#pragma once
#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "base/memory/linked_ptr.h"
#include "base/memory/scoped_ptr.h"
#include "base/message_loop_helpers.h"
#include "chrome/browser/profiles/profile_keyed_service.h"
#include "chrome/browser/protector/base_setting_change.h"
#include "chrome/browser/protector/settings_change_global_error_delegate.h"
class GURL;
class PrefService;
class Profile;
class TemplateURLService;
namespace protector {
class ProtectedPrefsWatcher;
class SettingsChangeGlobalError;
// Presents a SettingChange to user and handles possible user actions.
class ProtectorService : public ProfileKeyedService,
public SettingsChangeGlobalErrorDelegate {
public:
explicit ProtectorService(Profile* profile);
virtual ~ProtectorService();
// Shows global error about the specified change. Owns |change|. May be called
// multiple times in which case subsequent bubbles will be displayed.
virtual void ShowChange(BaseSettingChange* change);
// Returns |true| if a change is currently active (shown by a ShowChange call
// and not yet applied or discarded).
virtual bool IsShowingChange() const;
// Removes corresponding global error (including the bubbble if one is shown)
// and deletes the change instance (without calling Apply or Discard on it).
virtual void DismissChange(BaseSettingChange* change);
// Persists |change| and removes corresponding global error. |browser| is the
// Browser instance from which the user action originates.
virtual void ApplyChange(BaseSettingChange* change, Browser* browser);
// Discards |change| and removes corresponding global error. |browser| is the
// Browser instance from which the user action originates.
virtual void DiscardChange(BaseSettingChange* change, Browser* browser);
// Opens a tab with specified URL in the browser window we've shown error
// bubble for.
virtual void OpenTab(const GURL& url, Browser* browser);
// Returns the ProtectedPrefsWatcher instance for access to protected prefs
// backup.
ProtectedPrefsWatcher* GetPrefsWatcher();
// Returns the most recent change instance or NULL if there are no changes.
BaseSettingChange* GetLastChange();
// Returns the Profile instance for this service.
Profile* profile() { return profile_; }
private:
friend class ProtectorServiceTest;
// Pair of error and corresponding change instance. linked_ptr is used because
// Item instances are stored in a std::vector and must be copyable.
struct Item {
Item();
~Item();
linked_ptr<BaseSettingChange> change;
linked_ptr<SettingsChangeGlobalError> error;
};
// Matches Item by |change| field.
class MatchItemByChange {
public:
explicit MatchItemByChange(const BaseSettingChange* other);
bool operator()(const Item& item);
private:
const BaseSettingChange* other_;
};
// Matches Item by |error| field.
class MatchItemByError {
public:
explicit MatchItemByError(const SettingsChangeGlobalError* other);
bool operator()(const Item& item);
private:
const SettingsChangeGlobalError* other_;
};
// ProfileKeyedService implementation.
virtual void Shutdown() OVERRIDE;
// SettingsChangeGlobalErrorDelegate implementation.
virtual void OnApplyChange(SettingsChangeGlobalError* error,
Browser* browser) OVERRIDE;
virtual void OnDiscardChange(SettingsChangeGlobalError* error,
Browser* browser) OVERRIDE;
virtual void OnDecisionTimeout(SettingsChangeGlobalError* error) OVERRIDE;
virtual void OnRemovedFromProfile(SettingsChangeGlobalError* error) OVERRIDE;
// Pointers to error bubble controllers and corresponding changes in the order
// added.
std::vector<Item> items_;
// Profile which settings we are protecting.
Profile* profile_;
// True if there is a change that has been shown and not yet accepted or
// discarded by user.
bool has_active_change_;
// Observes changes to protected prefs and updates the backup.
scoped_ptr<ProtectedPrefsWatcher> prefs_watcher_;
DISALLOW_COPY_AND_ASSIGN(ProtectorService);
};
} // namespace protector
#endif // CHROME_BROWSER_PROTECTOR_PROTECTOR_SERVICE_H_
|