Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(691)

Side by Side Diff: chrome/browser/extensions/activity_log/activity_log_policy.h

Issue 18660004: Extension activity log database refactoring (step 1) (Closed) Base URL: http://git.chromium.org/chromium/src.git@incognito-tests
Patch Set: Delegate renaming and comment cleanup Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_ 5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_
6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_ 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_
7 7
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/files/file_path.h" 14 #include "base/files/file_path.h"
15 #include "base/memory/scoped_ptr.h" 15 #include "base/memory/scoped_ptr.h"
16 #include "base/timer/timer.h"
17 #include "base/values.h" 16 #include "base/values.h"
18 #include "chrome/browser/extensions/activity_log/activity_actions.h" 17 #include "chrome/browser/extensions/activity_log/activity_actions.h"
19 #include "content/public/browser/browser_thread.h" 18 #include "content/public/browser/browser_thread.h"
20 #include "url/gurl.h" 19 #include "url/gurl.h"
21 20
22 class Profile; 21 class Profile;
23 class GURL; 22 class GURL;
24 23
25 namespace extensions { 24 namespace extensions {
26 25
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 PARAM_KEY_URL_TITLE, 64 PARAM_KEY_URL_TITLE,
66 PARAM_KEY_DETAILS_STRING, 65 PARAM_KEY_DETAILS_STRING,
67 PARAM_KEY_EXTRA, 66 PARAM_KEY_EXTRA,
68 }; 67 };
69 68
70 // Parameters are the profile and the thread that will be used to execute 69 // Parameters are the profile and the thread that will be used to execute
71 // the callback when ReadData is called. 70 // the callback when ReadData is called.
72 // TODO(felt,dbabic) Since only ReadData uses thread_id, it would be 71 // TODO(felt,dbabic) Since only ReadData uses thread_id, it would be
73 // cleaner to pass thread_id as a param of ReadData directly. 72 // cleaner to pass thread_id as a param of ReadData directly.
74 explicit ActivityLogPolicy(Profile* profile); 73 explicit ActivityLogPolicy(Profile* profile);
75 virtual ~ActivityLogPolicy(); 74
75 // Instead of a public destructor, ActivityLogPolicy objects have a Close()
76 // method which will cause the object to be deleted (but may do so on another
77 // thread or in a deferred fashion).
78 virtual void Close() = 0;
76 79
77 // Updates the internal state of the model summarizing actions and possibly 80 // Updates the internal state of the model summarizing actions and possibly
78 // writes to the database. Implements the default policy storing internal 81 // writes to the database. Implements the default policy storing internal
79 // state to memory every 5 min. 82 // state to memory every 5 min.
80 virtual void ProcessAction( 83 virtual void ProcessAction(
81 ActionType action_type, 84 ActionType action_type,
82 const std::string& extension_id, 85 const std::string& extension_id,
83 const std::string& name, // action name 86 const std::string& name, // action name
84 const GURL& gurl, // target URL 87 const GURL& gurl, // target URL
85 const base::ListValue* args, // arguments 88 const base::ListValue* args, // arguments
86 const base::DictionaryValue* details) = 0; // details 89 const base::DictionaryValue* details) = 0; // details
87 90
88 // Saves the internal state in the memory into the database. Must be
89 // written so as to be thread-safe, as it can be called from a timer that
90 // saves state periodically and explicitly.
91 virtual void SaveState() { }
92
93 // Pass the parameters as a set of key-value pairs and return data back via 91 // Pass the parameters as a set of key-value pairs and return data back via
94 // a callback passing results as a set of key-value pairs. The keys are 92 // a callback passing results as a set of key-value pairs. The keys are
95 // policy-specific. 93 // policy-specific.
96 virtual void ReadData( 94 virtual void ReadData(
97 const base::DictionaryValue& parameters, 95 const base::DictionaryValue& parameters,
98 const base::Callback 96 const base::Callback
99 <void(scoped_ptr<base::DictionaryValue>)>& callback) const {} 97 <void(scoped_ptr<base::DictionaryValue>)>& callback) const {}
100 98
101 // TODO(felt,dbabic) This is overly specific to the current implementation 99 // TODO(felt,dbabic) This is overly specific to the current implementation
102 // of the FullStreamUIPolicy. We should refactor it to use the above 100 // of the FullStreamUIPolicy. We should refactor it to use the above
103 // more general member function. 101 // more general member function.
104 virtual void ReadData( 102 virtual void ReadData(
105 const std::string& extension_id, 103 const std::string& extension_id,
106 const int day, 104 const int day,
107 const base::Callback 105 const base::Callback
108 <void(scoped_ptr<std::vector<scoped_refptr<Action> > >)>& callback) 106 <void(scoped_ptr<std::vector<scoped_refptr<Action> > >)>& callback)
109 const {} 107 const {}
110 108
111 // For testing purposes --- disables periodic state saving, making the
112 // behavior reproducible.
113 virtual void SetSaveStateOnRequestOnly();
114
115 virtual std::string GetKey(KeyType key_id) const; 109 virtual std::string GetKey(KeyType key_id) const;
116 110
117 protected: 111 protected:
112 // An ActivityLogPolicy is not directly destroyed. Instead, call Close()
113 // which will cause the object to be deleted when it is safe.
114 virtual ~ActivityLogPolicy();
115
118 // The Schedule methods dispatch the calls to the database on a 116 // The Schedule methods dispatch the calls to the database on a
119 // separate thread. We dispatch to the UI thread if the DB thread doesn't 117 // separate thread. We dispatch to the UI thread if the DB thread doesn't
120 // exist, which should only happen in tests where there is no DB thread. 118 // exist, which should only happen in tests where there is no DB thread.
121 template<typename DatabaseType, typename DatabaseFunc> 119 template<typename DatabaseType, typename DatabaseFunc>
122 void ScheduleAndForget(DatabaseType db, DatabaseFunc func) { 120 void ScheduleAndForget(DatabaseType db, DatabaseFunc func) {
123 content::BrowserThread::PostTask( 121 content::BrowserThread::PostTask(
124 content::BrowserThread::DB, 122 content::BrowserThread::DB,
125 FROM_HERE, 123 FROM_HERE,
126 base::Bind(func, base::Unretained(db))); 124 base::Bind(func, base::Unretained(db)));
127 } 125 }
128 126
129 template<typename DatabaseType, typename DatabaseFunc, typename ArgA> 127 template<typename DatabaseType, typename DatabaseFunc, typename ArgA>
130 void ScheduleAndForget(DatabaseType db, DatabaseFunc func, ArgA a) { 128 void ScheduleAndForget(DatabaseType db, DatabaseFunc func, ArgA a) {
131 content::BrowserThread::PostTask( 129 content::BrowserThread::PostTask(
132 content::BrowserThread::DB, 130 content::BrowserThread::DB,
133 FROM_HERE, 131 FROM_HERE,
134 base::Bind(func, base::Unretained(db), a)); 132 base::Bind(func, base::Unretained(db), a));
135 } 133 }
136 134
137 template<typename DatabaseType, typename DatabaseFunc, 135 template<typename DatabaseType, typename DatabaseFunc,
138 typename ArgA, typename ArgB> 136 typename ArgA, typename ArgB>
139 void ScheduleAndForget(DatabaseType db, DatabaseFunc func, ArgA a, ArgB b) { 137 void ScheduleAndForget(DatabaseType db, DatabaseFunc func, ArgA a, ArgB b) {
140 content::BrowserThread::PostTask( 138 content::BrowserThread::PostTask(
141 content::BrowserThread::DB, 139 content::BrowserThread::DB,
142 FROM_HERE, 140 FROM_HERE,
143 base::Bind(func, base::Unretained(db), a, b)); 141 base::Bind(func, base::Unretained(db), a, b));
144 } 142 }
145 143
146 base::FilePath profile_base_path_; 144 base::FilePath profile_base_path_;
147 base::RepeatingTimer<ActivityLogPolicy> timer_; 145
146 private:
147 DISALLOW_COPY_AND_ASSIGN(ActivityLogPolicy);
148 }; 148 };
149 149
150 } // namespace extensions 150 } // namespace extensions
151 151
152 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_ 152 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_
OLDNEW
« no previous file with comments | « chrome/browser/extensions/activity_log/activity_log.cc ('k') | chrome/browser/extensions/activity_log/activity_log_policy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698