| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_HISTORY_HISTORY_EXTENSION_API_H_ | 5 #ifndef CHROME_BROWSER_HISTORY_HISTORY_EXTENSION_API_H_ |
| 6 #define CHROME_BROWSER_HISTORY_HISTORY_EXTENSION_API_H_ | 6 #define CHROME_BROWSER_HISTORY_HISTORY_EXTENSION_API_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 | 41 |
| 42 // Used for tracking registrations to history service notifications. | 42 // Used for tracking registrations to history service notifications. |
| 43 content::NotificationRegistrar registrar_; | 43 content::NotificationRegistrar registrar_; |
| 44 | 44 |
| 45 DISALLOW_COPY_AND_ASSIGN(HistoryExtensionEventRouter); | 45 DISALLOW_COPY_AND_ASSIGN(HistoryExtensionEventRouter); |
| 46 }; | 46 }; |
| 47 | 47 |
| 48 | 48 |
| 49 // Base class for history function APIs. | 49 // Base class for history function APIs. |
| 50 class HistoryFunction : public AsyncExtensionFunction { | 50 class HistoryFunction : public AsyncExtensionFunction { |
| 51 public: | 51 protected: |
| 52 virtual ~HistoryFunction() {} |
| 52 virtual void Run() OVERRIDE; | 53 virtual void Run() OVERRIDE; |
| 53 virtual bool RunImpl() = 0; | |
| 54 | 54 |
| 55 bool GetUrlFromValue(base::Value* value, GURL* url); | 55 bool GetUrlFromValue(base::Value* value, GURL* url); |
| 56 bool GetTimeFromValue(base::Value* value, base::Time* time); | 56 bool GetTimeFromValue(base::Value* value, base::Time* time); |
| 57 }; | 57 }; |
| 58 | 58 |
| 59 // Base class for history funciton APIs which require async interaction with | 59 // Base class for history funciton APIs which require async interaction with |
| 60 // chrome services and the extension thread. | 60 // chrome services and the extension thread. |
| 61 class HistoryFunctionWithCallback : public HistoryFunction { | 61 class HistoryFunctionWithCallback : public HistoryFunction { |
| 62 public: | 62 public: |
| 63 HistoryFunctionWithCallback(); | 63 HistoryFunctionWithCallback(); |
| 64 |
| 65 protected: |
| 64 virtual ~HistoryFunctionWithCallback(); | 66 virtual ~HistoryFunctionWithCallback(); |
| 65 | 67 |
| 68 // ExtensionFunction: |
| 69 virtual bool RunImpl() OVERRIDE; |
| 70 |
| 66 // Return true if the async call was completed, false otherwise. | 71 // Return true if the async call was completed, false otherwise. |
| 67 virtual bool RunAsyncImpl() = 0; | 72 virtual bool RunAsyncImpl() = 0; |
| 68 | 73 |
| 69 // Call this method to report the results of the async method to the caller. | 74 // Call this method to report the results of the async method to the caller. |
| 70 // This method calls Release(). | 75 // This method calls Release(). |
| 71 virtual void SendAsyncResponse(); | 76 virtual void SendAsyncResponse(); |
| 72 | 77 |
| 73 // Override HistoryFunction::RunImpl. | |
| 74 virtual bool RunImpl() OVERRIDE; | |
| 75 | |
| 76 protected: | |
| 77 // The consumer for the HistoryService callbacks. | 78 // The consumer for the HistoryService callbacks. |
| 78 CancelableRequestConsumer cancelable_consumer_; | 79 CancelableRequestConsumer cancelable_consumer_; |
| 79 | 80 |
| 80 private: | 81 private: |
| 81 // The actual call to SendResponse. This is required since the semantics for | 82 // The actual call to SendResponse. This is required since the semantics for |
| 82 // CancelableRequestConsumerT require it to be accessed after the call. | 83 // CancelableRequestConsumerT require it to be accessed after the call. |
| 83 void SendResponseToCallback(); | 84 void SendResponseToCallback(); |
| 84 }; | 85 }; |
| 85 | 86 |
| 86 class GetVisitsHistoryFunction : public HistoryFunctionWithCallback { | 87 class GetVisitsHistoryFunction : public HistoryFunctionWithCallback { |
| 87 public: | 88 public: |
| 88 // Override HistoryFunction. | 89 DECLARE_EXTENSION_FUNCTION_NAME("history.getVisits"); |
| 90 |
| 91 protected: |
| 92 virtual ~GetVisitsHistoryFunction() {} |
| 93 |
| 94 // HistoryFunctionWithCallback: |
| 89 virtual bool RunAsyncImpl() OVERRIDE; | 95 virtual bool RunAsyncImpl() OVERRIDE; |
| 90 DECLARE_EXTENSION_FUNCTION_NAME("history.getVisits"); | |
| 91 | 96 |
| 92 // Callback for the history function to provide results. | 97 // Callback for the history function to provide results. |
| 93 void QueryComplete(HistoryService::Handle request_service, | 98 void QueryComplete(HistoryService::Handle request_service, |
| 94 bool success, | 99 bool success, |
| 95 const history::URLRow* url_row, | 100 const history::URLRow* url_row, |
| 96 history::VisitVector* visits); | 101 history::VisitVector* visits); |
| 97 }; | 102 }; |
| 98 | 103 |
| 99 class SearchHistoryFunction : public HistoryFunctionWithCallback { | 104 class SearchHistoryFunction : public HistoryFunctionWithCallback { |
| 100 public: | 105 public: |
| 106 DECLARE_EXTENSION_FUNCTION_NAME("history.search"); |
| 107 |
| 108 protected: |
| 109 virtual ~SearchHistoryFunction() {} |
| 110 |
| 111 // HistoryFunctionWithCallback: |
| 101 virtual bool RunAsyncImpl() OVERRIDE; | 112 virtual bool RunAsyncImpl() OVERRIDE; |
| 102 DECLARE_EXTENSION_FUNCTION_NAME("history.search"); | |
| 103 | 113 |
| 104 // Callback for the history function to provide results. | 114 // Callback for the history function to provide results. |
| 105 void SearchComplete(HistoryService::Handle request_handle, | 115 void SearchComplete(HistoryService::Handle request_handle, |
| 106 history::QueryResults* results); | 116 history::QueryResults* results); |
| 107 }; | 117 }; |
| 108 | 118 |
| 109 class AddUrlHistoryFunction : public HistoryFunction { | 119 class AddUrlHistoryFunction : public HistoryFunction { |
| 110 public: | 120 public: |
| 121 DECLARE_EXTENSION_FUNCTION_NAME("history.addUrl"); |
| 122 |
| 123 protected: |
| 124 virtual ~AddUrlHistoryFunction() {} |
| 125 |
| 126 // HistoryFunctionWithCallback: |
| 111 virtual bool RunImpl() OVERRIDE; | 127 virtual bool RunImpl() OVERRIDE; |
| 112 DECLARE_EXTENSION_FUNCTION_NAME("history.addUrl"); | |
| 113 }; | 128 }; |
| 114 | 129 |
| 115 class DeleteAllHistoryFunction : public HistoryFunctionWithCallback { | 130 class DeleteAllHistoryFunction : public HistoryFunctionWithCallback { |
| 116 public: | 131 public: |
| 132 DECLARE_EXTENSION_FUNCTION_NAME("history.deleteAll"); |
| 133 |
| 134 protected: |
| 135 virtual ~DeleteAllHistoryFunction() {} |
| 136 |
| 137 // HistoryFunctionWithCallback: |
| 117 virtual bool RunAsyncImpl() OVERRIDE; | 138 virtual bool RunAsyncImpl() OVERRIDE; |
| 118 DECLARE_EXTENSION_FUNCTION_NAME("history.deleteAll"); | |
| 119 | 139 |
| 120 // Callback for the history service to acknowledge deletion. | 140 // Callback for the history service to acknowledge deletion. |
| 121 void DeleteComplete(); | 141 void DeleteComplete(); |
| 122 }; | 142 }; |
| 123 | 143 |
| 124 | 144 |
| 125 class DeleteUrlHistoryFunction : public HistoryFunction { | 145 class DeleteUrlHistoryFunction : public HistoryFunction { |
| 126 public: | 146 public: |
| 147 DECLARE_EXTENSION_FUNCTION_NAME("history.deleteUrl"); |
| 148 |
| 149 protected: |
| 150 virtual ~DeleteUrlHistoryFunction() {} |
| 151 |
| 152 // HistoryFunctionWithCallback: |
| 127 virtual bool RunImpl() OVERRIDE; | 153 virtual bool RunImpl() OVERRIDE; |
| 128 DECLARE_EXTENSION_FUNCTION_NAME("history.deleteUrl"); | |
| 129 }; | 154 }; |
| 130 | 155 |
| 131 class DeleteRangeHistoryFunction : public HistoryFunctionWithCallback { | 156 class DeleteRangeHistoryFunction : public HistoryFunctionWithCallback { |
| 132 public: | 157 public: |
| 158 DECLARE_EXTENSION_FUNCTION_NAME("history.deleteRange"); |
| 159 |
| 160 protected: |
| 161 virtual ~DeleteRangeHistoryFunction() {} |
| 162 |
| 163 // HistoryFunctionWithCallback: |
| 133 virtual bool RunAsyncImpl() OVERRIDE; | 164 virtual bool RunAsyncImpl() OVERRIDE; |
| 134 DECLARE_EXTENSION_FUNCTION_NAME("history.deleteRange"); | |
| 135 | 165 |
| 136 // Callback for the history service to acknowledge deletion. | 166 // Callback for the history service to acknowledge deletion. |
| 137 void DeleteComplete(); | 167 void DeleteComplete(); |
| 138 }; | 168 }; |
| 139 | 169 |
| 140 #endif // CHROME_BROWSER_HISTORY_HISTORY_EXTENSION_API_H_ | 170 #endif // CHROME_BROWSER_HISTORY_HISTORY_EXTENSION_API_H_ |
| OLD | NEW |