17d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 27d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 37d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// found in the LICENSE file. 47d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 57d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#ifndef CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_FULLSTREAM_UI_POLICY_H_ 67d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#define CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_FULLSTREAM_UI_POLICY_H_ 77d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 87d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include <string> 9a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 107dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/extensions/activity_log/activity_database.h" 117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/browser/extensions/activity_log/activity_log_policy.h" 127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)class GURL; 147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)namespace extensions { 167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// A policy for logging the full stream of actions, including all arguments. 187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)// It's mostly intended to be used in testing and analysis. 19ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// 20ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// NOTE: The FullStreamUIPolicy deliberately keeps almost all information, 21ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// including some data that could be privacy sensitive (full URLs including 22ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// incognito URLs, full headers when WebRequest is used, etc.). It should not 23ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch// be used during normal browsing if users care about privacy. 24a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)class FullStreamUIPolicy : public ActivityLogDatabasePolicy { 257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) public: 267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // For more info about these member functions, see the super class. 277d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) explicit FullStreamUIPolicy(Profile* profile); 287d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 29558790d6acca3451cf3a6b497803a5f07d0bec58Ben Murdoch virtual void ProcessAction(scoped_refptr<Action> action) OVERRIDE; 307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 31424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual void ReadFilteredData( 32424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const std::string& extension_id, 33424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const Action::ActionType type, 34424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const std::string& api_name, 35424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const std::string& page_url, 36424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const std::string& arg_url, 3758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const int days_ago, 38424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const base::Callback 39424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) <void(scoped_ptr<Action::ActionVector>)>& callback) OVERRIDE; 40424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 417dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual void Close() OVERRIDE; 427dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 435d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // Remove the actions stored for this policy according to the passed IDs. 445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) virtual void RemoveActions(const std::vector<int64>& action_ids) OVERRIDE; 455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 46424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Clean the URL data stored for this policy. 47424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) virtual void RemoveURLs(const std::vector<GURL>& restrict_urls) OVERRIDE; 48424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 49d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Clean the data related to this extension for this policy. 50d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) virtual void RemoveExtensionData(const std::string& extension_id) OVERRIDE; 51d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 5258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Delete everything in the database. 5358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) virtual void DeleteDatabase() OVERRIDE; 5458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 55ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch // Database table schema. 56ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch static const char* kTableName; 57ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch static const char* kTableContentFields[]; 58ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch static const char* kTableFieldTypes[]; 59ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch static const int kTableFieldCount; 60ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 617d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) protected: 627dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // Only ever run by OnDatabaseClose() below; see the comments on the 637dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch // ActivityDatabase class for an overall discussion of how cleanup works. 64a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) virtual ~FullStreamUIPolicy(); 657dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 66ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // The ActivityDatabase::Delegate interface. These are always called from 67ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch // the database thread. 68a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) virtual bool InitDatabase(sql::Connection* db) OVERRIDE; 69a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) virtual bool FlushDatabase(sql::Connection* db) OVERRIDE; 70a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) virtual void OnDatabaseFailure() OVERRIDE; 717dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch virtual void OnDatabaseClose() OVERRIDE; 727dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch 73a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Strips arguments if needed by policy. May return the original object (if 74a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // unmodified), or a copy (if modifications were made). The implementation 75a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // in FullStreamUIPolicy returns the action unmodified. 76a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) virtual scoped_refptr<Action> ProcessArguments( 77a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) scoped_refptr<Action> action) const; 78ca12bfac764ba476d6cd062bf1dde12cc64c3f40Ben Murdoch 795d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // The implementation of RemoveActions; this must only run on the database 805d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) // thread. 815d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) void DoRemoveActions(const std::vector<int64>& action_ids); 825d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) 83424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // The implementation of RemoveURLs; this must only run on the database 84424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // thread. 8558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) void DoRemoveURLs(const std::vector<GURL>& restrict_urls); 8658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 87d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // The implementation of RemoveExtensionData; this must only run on the 88d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // database thread. 89d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void DoRemoveExtensionData(const std::string& extension_id); 90d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 9158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // The implementation of DeleteDatabase; this must only run on the database 9258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // thread. 9358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) void DoDeleteDatabase(); 94424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 95a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Tracks any pending updates to be written to the database, if write 96a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // batching is turned on. Should only be accessed from the database thread. 97a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Action::ActionVector queued_actions_; 987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 99a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) private: 100a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Adds an Action to queued_actions_; this should be invoked only on the 101a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // database thread. 102a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) void QueueAction(scoped_refptr<Action> action); 1037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 104424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Internal method to read data from the database; called on the database 105424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // thread. 106424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) scoped_ptr<Action::ActionVector> DoReadFilteredData( 107424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const std::string& extension_id, 108424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const Action::ActionType type, 109424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const std::string& api_name, 110424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) const std::string& page_url, 11158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const std::string& arg_url, 11258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const int days_ago); 1137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)}; 1147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} // namespace extensions 1167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#endif // CHROME_BROWSER_EXTENSIONS_ACTIVITY_LOG_FULLSTREAM_UI_POLICY_H_ 118