Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / chrome / browser / extensions / activity_log / fullstream_ui_policy.h
blobf468e11abf3da20da5a9154ea9e25a6b9e8e4941
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
3 // found in the LICENSE file.
5 #ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_FULLSTREAM_UI_POLICY_H_
6 #define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_FULLSTREAM_UI_POLICY_H_
8 #include <string>
10 #include "chrome/browser/extensions/activity_log/activity_database.h"
11 #include "chrome/browser/extensions/activity_log/activity_log_policy.h"
13 class GURL;
15 namespace extensions {
17 // A policy for logging the full stream of actions, including all arguments.
18 // It's mostly intended to be used in testing and analysis.
20 // NOTE: The FullStreamUIPolicy deliberately keeps almost all information,
21 // including some data that could be privacy sensitive (full URLs including
22 // incognito URLs, full headers when WebRequest is used, etc.). It should not
23 // be used during normal browsing if users care about privacy.
24 class FullStreamUIPolicy : public ActivityLogDatabasePolicy {
25 public:
26 // For more info about these member functions, see the super class.
27 explicit FullStreamUIPolicy(Profile* profile);
29 void ProcessAction(scoped_refptr<Action> action) override;
31 void ReadFilteredData(
32 const std::string& extension_id,
33 const Action::ActionType type,
34 const std::string& api_name,
35 const std::string& page_url,
36 const std::string& arg_url,
37 const int days_ago,
38 const base::Callback<void(scoped_ptr<Action::ActionVector>)>& callback)
39 override;
41 void Close() override;
43 // Remove the actions stored for this policy according to the passed IDs.
44 void RemoveActions(const std::vector<int64>& action_ids) override;
46 // Clean the URL data stored for this policy.
47 void RemoveURLs(const std::vector<GURL>& restrict_urls) override;
49 // Clean the data related to this extension for this policy.
50 void RemoveExtensionData(const std::string& extension_id) override;
52 // Delete everything in the database.
53 void DeleteDatabase() override;
55 // Database table schema.
56 static const char kTableName[];
57 static const char* const kTableContentFields[];
58 static const char* const kTableFieldTypes[];
59 static const int kTableFieldCount;
61 protected:
62 // Only ever run by OnDatabaseClose() below; see the comments on the
63 // ActivityDatabase class for an overall discussion of how cleanup works.
64 ~FullStreamUIPolicy() override;
66 // The ActivityDatabase::Delegate interface. These are always called from
67 // the database thread.
68 bool InitDatabase(sql::Connection* db) override;
69 bool FlushDatabase(sql::Connection* db) override;
70 void OnDatabaseFailure() override;
71 void OnDatabaseClose() override;
73 // Strips arguments if needed by policy. May return the original object (if
74 // unmodified), or a copy (if modifications were made). The implementation
75 // in FullStreamUIPolicy returns the action unmodified.
76 virtual scoped_refptr<Action> ProcessArguments(
77 scoped_refptr<Action> action) const;
79 // The implementation of RemoveActions; this must only run on the database
80 // thread.
81 void DoRemoveActions(const std::vector<int64>& action_ids);
83 // The implementation of RemoveURLs; this must only run on the database
84 // thread.
85 void DoRemoveURLs(const std::vector<GURL>& restrict_urls);
87 // The implementation of RemoveExtensionData; this must only run on the
88 // database thread.
89 void DoRemoveExtensionData(const std::string& extension_id);
91 // The implementation of DeleteDatabase; this must only run on the database
92 // thread.
93 void DoDeleteDatabase();
95 // Tracks any pending updates to be written to the database, if write
96 // batching is turned on. Should only be accessed from the database thread.
97 Action::ActionVector queued_actions_;
99 private:
100 // Adds an Action to queued_actions_; this should be invoked only on the
101 // database thread.
102 void QueueAction(scoped_refptr<Action> action);
104 // Internal method to read data from the database; called on the database
105 // thread.
106 scoped_ptr<Action::ActionVector> DoReadFilteredData(
107 const std::string& extension_id,
108 const Action::ActionType type,
109 const std::string& api_name,
110 const std::string& page_url,
111 const std::string& arg_url,
112 const int days_ago);
115 } // namespace extensions
117 #endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_FULLSTREAM_UI_POLICY_H_