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

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: 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 virtual void Close() = 0;
76 76
77 // Updates the internal state of the model summarizing actions and possibly 77 // Updates the internal state of the model summarizing actions and possibly
78 // writes to the database. Implements the default policy storing internal 78 // writes to the database. Implements the default policy storing internal
79 // state to memory every 5 min. 79 // state to memory every 5 min.
80 virtual void ProcessAction( 80 virtual void ProcessAction(
81 ActionType action_type, 81 ActionType action_type,
82 const std::string& extension_id, 82 const std::string& extension_id,
83 const std::string& name, // action name 83 const std::string& name, // action name
84 const GURL& gurl, // target URL 84 const GURL& gurl, // target URL
85 const base::ListValue* args, // arguments 85 const base::ListValue* args, // arguments
86 const base::DictionaryValue* details) = 0; // details 86 const base::DictionaryValue* details) = 0; // details
87 87
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 88 // 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 89 // a callback passing results as a set of key-value pairs. The keys are
95 // policy-specific. 90 // policy-specific.
96 virtual void ReadData( 91 virtual void ReadData(
97 const base::DictionaryValue& parameters, 92 const base::DictionaryValue& parameters,
98 const base::Callback 93 const base::Callback
99 <void(scoped_ptr<base::DictionaryValue>)>& callback) const {} 94 <void(scoped_ptr<base::DictionaryValue>)>& callback) const {}
100 95
101 // TODO(felt,dbabic) This is overly specific to the current implementation 96 // TODO(felt,dbabic) This is overly specific to the current implementation
102 // of the FullStreamUIPolicy. We should refactor it to use the above 97 // of the FullStreamUIPolicy. We should refactor it to use the above
103 // more general member function. 98 // more general member function.
104 virtual void ReadData( 99 virtual void ReadData(
105 const std::string& extension_id, 100 const std::string& extension_id,
106 const int day, 101 const int day,
107 const base::Callback 102 const base::Callback
108 <void(scoped_ptr<std::vector<scoped_refptr<Action> > >)>& callback) 103 <void(scoped_ptr<std::vector<scoped_refptr<Action> > >)>& callback)
109 const {} 104 const {}
110 105
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; 106 virtual std::string GetKey(KeyType key_id) const;
116 107
117 protected: 108 protected:
109 // An ActivityLogPolicy is not directly destroyed. Instead, call Close()
110 // which will cause the object to be deleted when it is safe.
111 virtual ~ActivityLogPolicy();
112
118 // The Schedule methods dispatch the calls to the database on a 113 // 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 114 // 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. 115 // exist, which should only happen in tests where there is no DB thread.
121 template<typename DatabaseType, typename DatabaseFunc> 116 template<typename DatabaseType, typename DatabaseFunc>
122 void ScheduleAndForget(DatabaseType db, DatabaseFunc func) { 117 void ScheduleAndForget(DatabaseType db, DatabaseFunc func) {
123 content::BrowserThread::PostTask( 118 content::BrowserThread::PostTask(
124 content::BrowserThread::DB, 119 content::BrowserThread::DB,
125 FROM_HERE, 120 FROM_HERE,
126 base::Bind(func, base::Unretained(db))); 121 base::Bind(func, base::Unretained(db)));
127 } 122 }
128 123
129 template<typename DatabaseType, typename DatabaseFunc, typename ArgA> 124 template<typename DatabaseType, typename DatabaseFunc, typename ArgA>
130 void ScheduleAndForget(DatabaseType db, DatabaseFunc func, ArgA a) { 125 void ScheduleAndForget(DatabaseType db, DatabaseFunc func, ArgA a) {
131 content::BrowserThread::PostTask( 126 content::BrowserThread::PostTask(
132 content::BrowserThread::DB, 127 content::BrowserThread::DB,
133 FROM_HERE, 128 FROM_HERE,
134 base::Bind(func, base::Unretained(db), a)); 129 base::Bind(func, base::Unretained(db), a));
135 } 130 }
136 131
137 template<typename DatabaseType, typename DatabaseFunc, 132 template<typename DatabaseType, typename DatabaseFunc,
138 typename ArgA, typename ArgB> 133 typename ArgA, typename ArgB>
139 void ScheduleAndForget(DatabaseType db, DatabaseFunc func, ArgA a, ArgB b) { 134 void ScheduleAndForget(DatabaseType db, DatabaseFunc func, ArgA a, ArgB b) {
140 content::BrowserThread::PostTask( 135 content::BrowserThread::PostTask(
141 content::BrowserThread::DB, 136 content::BrowserThread::DB,
142 FROM_HERE, 137 FROM_HERE,
143 base::Bind(func, base::Unretained(db), a, b)); 138 base::Bind(func, base::Unretained(db), a, b));
144 } 139 }
145 140
146 base::FilePath profile_base_path_; 141 base::FilePath profile_base_path_;
147 base::RepeatingTimer<ActivityLogPolicy> timer_; 142
143 private:
144 DISALLOW_COPY_AND_ASSIGN(ActivityLogPolicy);
148 }; 145 };
149 146
150 } // namespace extensions 147 } // namespace extensions
151 148
152 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_ 149 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698