summaryrefslogtreecommitdiffstats
path: root/chrome/browser/extensions/extension_history_api.h
diff options
context:
space:
mode:
authorbrg@chromium.com <brg@chromium.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-30 05:25:01 +0000
committerbrg@chromium.com <brg@chromium.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-10-30 05:25:01 +0000
commitde768a837346f2f78fbc5368bdf1d0c8e37c8f10 (patch)
treeaf9fadc824793d3f9fef771ac312e1e371ee5ded /chrome/browser/extensions/extension_history_api.h
parentd4e58f35f5d7091aa3ba483e1c02b454b6bfd3f2 (diff)
downloadchromium_src-de768a837346f2f78fbc5368bdf1d0c8e37c8f10.zip
chromium_src-de768a837346f2f78fbc5368bdf1d0c8e37c8f10.tar.gz
chromium_src-de768a837346f2f78fbc5368bdf1d0c8e37c8f10.tar.bz2
Implement the Extension History API, v 0.1.The first version is a weak wrapper around the HistoryServices object in Chrome.BUG=22952TEST=browser_tests.exe --gtest_filer=ExtensionApiTest.History
Review URL: http://codereview.chromium.org/313001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@30561 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/extensions/extension_history_api.h')
-rw-r--r--chrome/browser/extensions/extension_history_api.h149
1 files changed, 149 insertions, 0 deletions
diff --git a/chrome/browser/extensions/extension_history_api.h b/chrome/browser/extensions/extension_history_api.h
new file mode 100644
index 0000000..184fbb2
--- /dev/null
+++ b/chrome/browser/extensions/extension_history_api.h
@@ -0,0 +1,149 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CHROME_BROWSER_EXTENSIONS_EXTENSION_HISTORY_API_H_
+#define CHROME_BROWSER_EXTENSIONS_EXTENSION_HISTORY_API_H_
+
+#include <map>
+#include <string>
+
+#include "base/singleton.h"
+#include "chrome/browser/history/history.h"
+#include "chrome/browser/history/history_notifications.h"
+#include "chrome/browser/extensions/extension_function.h"
+#include "chrome/common/notification_registrar.h"
+
+// Observes History service and routes the notifications as events to the
+// extension system.
+class ExtensionHistoryEventRouter : public NotificationObserver {
+ public:
+ // Single instance of the event router.
+ static ExtensionHistoryEventRouter* GetInstance();
+
+ // Safe to call multiple times.
+ void ObserveProfile(Profile* profile);
+
+ private:
+ friend struct DefaultSingletonTraits<ExtensionHistoryEventRouter>;
+
+ ExtensionHistoryEventRouter() {}
+ virtual ~ExtensionHistoryEventRouter() {}
+
+ // NotificationObserver::Observe.
+ virtual void Observe(NotificationType type,
+ const NotificationSource& source,
+ const NotificationDetails& details);
+
+ void HistoryUrlVisited(Profile* profile,
+ const history::URLVisitedDetails* details);
+
+ void HistoryUrlsRemoved(Profile* profile,
+ const history::URLsDeletedDetails* details);
+
+ void DispatchEvent(Profile* profile,
+ const char* event_name,
+ const std::string& json_args);
+
+ // Used for tracking registrations to history service notifications.
+ NotificationRegistrar registrar_;
+
+ // Registered profiles.
+ typedef std::map<uintptr_t, Profile*> ProfileMap;
+ ProfileMap profiles_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExtensionHistoryEventRouter);
+};
+
+
+// Base class for history function APIs.
+class HistoryFunction : public AsyncExtensionFunction {
+ public:
+ virtual void Run();
+ virtual bool RunImpl() = 0;
+
+ bool GetUrlFromValue(Value* value, GURL* url);
+ bool GetTimeFromValue(Value* value, base::Time* time);
+};
+
+// Base class for history funciton APIs which require async interaction with
+// chrome services and the extension thread.
+class HistoryFunctionWithCallback : public HistoryFunction {
+ public:
+ // Return true if the async call was completed, false otherwise.
+ virtual bool RunAsyncImpl() = 0;
+
+ // Call this method to report the results of the async method to the caller.
+ // This method calls Release().
+ virtual void SendAsyncResponse();
+
+ // Override HistoryFunction::RunImpl.
+ virtual bool RunImpl();
+
+ protected:
+ // The consumer for the HistoryService callbacks.
+ CancelableRequestConsumer cancelable_consumer_;
+
+ private:
+ // The actual call to SendReposne. This is required since the semantics for
+ // CancelableRequestConsumerT require it to be accessed after the call.
+ void SendResponseToCallback();
+
+ friend class NewRunnableMethod;
+};
+
+class GetVisitsHistoryFunction : public HistoryFunctionWithCallback {
+ public:
+ // Override HistoryFunction.
+ virtual bool RunAsyncImpl();
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.history.getVisits");
+
+ // Callback for the history function to provide results.
+ void QueryComplete(HistoryService::Handle request_service,
+ bool success,
+ const history::URLRow* url_row,
+ history::VisitVector* visits);
+};
+
+class SearchHistoryFunction : public HistoryFunctionWithCallback {
+ public:
+ virtual bool RunAsyncImpl();
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.history.search");
+
+ // Callback for the history function to provide results.
+ void SearchComplete(HistoryService::Handle request_handle,
+ history::QueryResults* results);
+};
+
+class AddUrlHistoryFunction : public HistoryFunction {
+ public:
+ virtual bool RunImpl();
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.history.addUrl");
+};
+
+class DeleteAllHistoryFunction : public HistoryFunctionWithCallback {
+ public:
+ virtual bool RunAsyncImpl();
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.history.deleteAll");
+
+ // Callback for the history service to acknowledge deletion.
+ void DeleteComplete();
+};
+
+
+class DeleteUrlHistoryFunction : public HistoryFunction {
+ public:
+ virtual bool RunImpl();
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.history.deleteUrl");
+};
+
+class DeleteRangeHistoryFunction : public HistoryFunctionWithCallback {
+ public:
+ virtual bool RunAsyncImpl();
+ DECLARE_EXTENSION_FUNCTION_NAME("experimental.history.deleteRange");
+
+ // Callback for the history service to acknowledge deletion.
+ void DeleteComplete();
+};
+
+#endif // CHROME_BROWSER_EXTENSIONS_EXTENSION_HISTORY_API_H_