Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
|
felt
2013/05/22 21:17:59
The style guide was updated very recently -- can y
dbabic
2013/05/23 01:35:04
Done.
| |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_ | |
| 6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_ | |
| 7 | |
| 8 #include <string> | |
| 9 #include <vector> | |
| 10 | |
| 11 #include "base/callback.h" | |
| 12 #include "base/files/file_path.h" | |
| 13 #include "base/memory/scoped_ptr.h" | |
| 14 #include "base/time.h" | |
| 15 #include "base/values.h" | |
| 16 #include "chrome/browser/extensions/activity_log/activity_actions.h" | |
| 17 #include "googleurl/src/gurl.h" | |
| 18 | |
| 19 class Profile; | |
| 20 class GURL; | |
| 21 | |
| 22 namespace extensions { | |
| 23 | |
| 24 class Extension; | |
| 25 | |
| 26 // Abstract class for summarizing data and storing it into the database. Any | |
| 27 // subclass should implement the following functionality: | |
| 28 // | |
| 29 // (1) Summarization (and possibly) compression of data | |
| 30 // (2) Periodical syncing of the in-memory state with the database | |
| 31 // (3) Periodical database cleanup | |
| 32 // | |
| 33 // Since every policy implementation might summarize data differently, the | |
| 34 // database implementation is policy-specific and therefore completely | |
| 35 // encapsulated in the policy class. | |
| 36 class ActivityLogPolicy { | |
| 37 public: | |
| 38 enum ActionType { | |
| 39 ACTION_API, | |
| 40 ACTION_EVENT, | |
| 41 ACTION_BLOCKED, | |
| 42 ACTION_DOM, | |
| 43 ACTION_WEB_REQUEST, | |
| 44 ACTION_ON_SCRIPTS, | |
|
felt
2013/05/22 21:17:59
Is there a reason why you separate this out into m
dbabic
2013/05/23 01:35:04
Done.
You are probably referring to the ON_SCRIPT
| |
| 45 }; | |
| 46 | |
| 47 // For all subclasses, add all the key types they might support here. | |
| 48 // The actual key is returned by calling GetKey(KeyType). The subclasses | |
| 49 // are free to return an empty string for keys they don't support. | |
| 50 // For every key added here, you should update the GetKey member function | |
| 51 // for at least one policy. | |
| 52 enum KeyType { | |
| 53 PARAM_KEY_REASON, // Why an action was blocked | |
| 54 PARAM_KEY_DOM_ACTION, // Getter, Setter, Method,... | |
| 55 PARAM_KEY_URL_TITLE, | |
| 56 PARAM_KEY_DETAILS_STRING, | |
| 57 /* | |
| 58 More PARAM_KEY_... | |
| 59 UI_KEY_... | |
|
felt
2013/05/22 21:17:59
Please delete the /* ... */
dbabic
2013/05/23 01:35:04
Done.
| |
| 60 */ | |
| 61 }; | |
| 62 | |
| 63 explicit ActivityLogPolicy(Profile*); | |
| 64 virtual ~ActivityLogPolicy() {} | |
| 65 | |
| 66 // Updates the internal state of the model summarizing actions and possibly | |
| 67 // writes to the database. Implements the default policy storing internal | |
| 68 // state to memory every 5 min. | |
| 69 virtual void ProcessAction( | |
| 70 ActionType, | |
| 71 const Extension&, | |
|
felt
2013/05/22 21:17:59
All parameters should be named. This goes for all
dbabic
2013/05/23 01:35:04
Done.
| |
| 72 const std::string& /* action name */, | |
| 73 const GURL* /* target URL */, | |
| 74 const base::ListValue* /* arguments */, | |
|
felt
2013/05/22 21:17:59
For consistency, switch to the // style of comment
dbabic
2013/05/23 01:35:04
Done.
| |
| 75 const base::DictionaryValue* /* details */ | |
| 76 ); | |
| 77 | |
| 78 // Saves the internal state in the memory into the database | |
| 79 virtual void SaveState() = 0; | |
| 80 | |
| 81 // Pass the parameters as a set of key-value pairs and return data back via | |
| 82 // a callback passing results as a set of key-value pairs. The keys are | |
| 83 // policy-specific. | |
| 84 virtual void ReadData( | |
| 85 const base::DictionaryValue&, | |
| 86 const base::Callback<void(scoped_ptr<base::DictionaryValue>)>&) const {} | |
| 87 | |
| 88 // TODO(felt,dbabic) This is overly specific to the current implementation | |
| 89 // of the FullStreamUIPolicy. We should refractor it to use the above | |
| 90 // more general member function. | |
| 91 virtual void ReadData(const std::string& extension_id, const int day, | |
| 92 const | |
| 93 base::Callback<void(scoped_ptr<std::vector<scoped_refptr<Action> > >)>&) | |
| 94 const {} | |
| 95 | |
| 96 // For testing purposes --- disables periodic sync, making the behavior | |
| 97 // reproducible. | |
|
felt
2013/05/22 21:17:59
Can you rename to not use "Sync", since that is us
dbabic
2013/05/23 01:35:04
Done.
I feel that calling it "batching" is a bit
| |
| 98 void SetSyncOnRequestOnly() { | |
| 99 sync_on_request_only_ = true; | |
| 100 } | |
| 101 | |
| 102 virtual void GetKey(KeyType, std::string& key) const; | |
| 103 | |
| 104 protected: | |
|
felt
2013/05/22 21:17:59
Why are these protected instead of private? (Is it
dbabic
2013/05/23 01:35:04
Done.
Good question for DoProcessAction, I remove
| |
| 105 // Processes the action and (only) updates the internal state. | |
| 106 virtual void DoProcessAction(ActionType, const Extension&, | |
|
felt
2013/05/22 21:17:59
Please take a look at https://google-styleguide.go
dbabic
2013/05/23 01:35:04
Done.
| |
| 107 const std::string&, const GURL*, const base::ListValue*, | |
| 108 const base::DictionaryValue*) = 0; | |
| 109 | |
| 110 base::Time last_sync_timestamp_; | |
|
felt
2013/05/22 21:17:59
What is this for? Why not implement this with the
dbabic
2013/05/23 01:35:04
That's the periodic state saving feature Ulfar sug
felt
2013/05/23 04:20:01
I think there is some confusion -- Ulfar wasn't su
dbabic
2013/05/24 00:35:07
Ok. Done.
| |
| 111 base::FilePath profile_base_path_; | |
| 112 bool sync_on_request_only_; | |
|
felt
2013/05/22 21:17:59
What does this variable name mean? Is it equivalen
dbabic
2013/05/23 01:35:04
Yes. I've renamed it now: _sync_ -> _save_state_
| |
| 113 }; | |
| 114 | |
| 115 } // End of the extensions namespace | |
| 116 | |
| 117 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_ACTIVITY_LOG_POLICY_H_ | |
| OLD | NEW |