Index: chrome/browser/in_process_webkit/indexed_db_key_utility_client.h |
diff --git a/chrome/browser/in_process_webkit/indexed_db_key_utility_client.h b/chrome/browser/in_process_webkit/indexed_db_key_utility_client.h |
index 3a79c282be520b8bfa973c23b68d6a2eb96b9e04..b36aafa12b67bea09d73ab67d5b3b6c23e440afd 100644 |
--- a/chrome/browser/in_process_webkit/indexed_db_key_utility_client.h |
+++ b/chrome/browser/in_process_webkit/indexed_db_key_utility_client.h |
@@ -6,87 +6,43 @@ |
#define CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_KEY_UTILITY_CLIENT_H_ |
#pragma once |
+#include <vector> |
+ |
#include "base/ref_counted.h" |
-#include "base/synchronization/waitable_event.h" |
-#include "chrome/browser/utility_process_host.h" |
+#include "base/string16.h" |
class IndexedDBKey; |
class SerializedScriptValue; |
+class KeyUtilityClientImpl; |
-// This class is responsible to obtain IndexedDBKeys from the |
-// SerializedScriptValues given an IDBKeyPath. It uses UtilityProcess to do this |
-// inside a sandbox (a V8 lock is required there). At this level, all methods |
-// are synchronous as required by the caller. The public API is used on |
-// WEBKIT thread, but internally it moves around to UI and IO as needed. |
-class IndexedDBKeyUtilityClient |
- : public base::RefCountedThreadSafe<IndexedDBKeyUtilityClient> { |
- public: |
- IndexedDBKeyUtilityClient(); |
- |
- // Starts the UtilityProcess. Must be called before any other method. |
- void StartUtilityProcess(); |
- |
- // Ends the UtilityProcess. Must be called after StartUtilityProcess() and |
- // before destruction. |
- // TODO(bulach): figure out an appropriate hook so that we can keep the |
- // UtilityProcess running for a longer period of time and avoid spinning it |
- // on every IDBObjectStore::Put call. |
- void EndUtilityProcess(); |
+namespace base { |
+template <typename T> |
+struct DefaultLazyInstanceTraits; |
+} // namespace base |
+// Class for obtaining IndexedDBKeys from the SerializedScriptValues given |
+// an IDBKeyPath. This class is a thin singleton wrapper around the |
+// KeyUtilityClientImpl, which does the real work. |
+class IndexedDBKeyUtilityClient { |
+ public: |
// Synchronously obtain the |keys| from |values| for the given |key_path|. |
- void CreateIDBKeysFromSerializedValuesAndKeyPath( |
+ static void CreateIDBKeysFromSerializedValuesAndKeyPath( |
const std::vector<SerializedScriptValue>& values, |
const string16& key_path, |
std::vector<IndexedDBKey>* keys); |
- private: |
- class Client : public UtilityProcessHost::Client { |
- public: |
- explicit Client(IndexedDBKeyUtilityClient* parent); |
- |
- // UtilityProcessHost::Client |
- virtual void OnProcessCrashed(int exit_code); |
- virtual void OnIDBKeysFromValuesAndKeyPathSucceeded( |
- int id, const std::vector<IndexedDBKey>& keys); |
- virtual void OnIDBKeysFromValuesAndKeyPathFailed(int id); |
- |
- private: |
- IndexedDBKeyUtilityClient* parent_; |
+ // Shut down the underlying implementation. Must be called on the IO thread. |
+ static void Shutdown(); |
- DISALLOW_COPY_AND_ASSIGN(Client); |
- }; |
- |
- friend class base::RefCountedThreadSafe<IndexedDBKeyUtilityClient>; |
+ private: |
+ friend struct base::DefaultLazyInstanceTraits<IndexedDBKeyUtilityClient>; |
+ IndexedDBKeyUtilityClient(); |
~IndexedDBKeyUtilityClient(); |
- void GetRDHAndStartUtilityProcess(); |
- void StartUtilityProcessInternal(ResourceDispatcherHost* rdh); |
- void EndUtilityProcessInternal(); |
- void CallStartIDBKeyFromValueAndKeyPathFromIOThread( |
- const std::vector<SerializedScriptValue>& values, |
- const string16& key_path); |
- |
- void SetKeys(const std::vector<IndexedDBKey>& keys); |
- void FinishCreatingKeys(); |
- |
- base::WaitableEvent waitable_event_; |
- |
- // Used in both IO and WEBKIT threads, but guarded by WaitableEvent, i.e., |
- // these members are only set / read when the other thread is blocked. |
- enum State { |
- STATE_UNINITIALIZED, |
- STATE_INITIALIZED, |
- STATE_CREATING_KEYS, |
- STATE_SHUTDOWN, |
- }; |
- State state_; |
- std::vector<IndexedDBKey> keys_; |
- |
- // Used in the IO thread. |
- UtilityProcessHost* utility_process_host_; |
- scoped_refptr<Client> client_; |
+ bool is_shutdown_; |
- DISALLOW_COPY_AND_ASSIGN(IndexedDBKeyUtilityClient); |
+ // The real client; laziliy instantiated. |
+ scoped_refptr<KeyUtilityClientImpl> impl_; |
}; |
#endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_KEY_UTILITY_CLIENT_H_ |