Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_IN_PROCESS_WEBKIT_INDEXED_DB_KEY_UTILITY_CLIENT_H_ | 5 #ifndef CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_KEY_UTILITY_CLIENT_H_ |
| 6 #define CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_KEY_UTILITY_CLIENT_H_ | 6 #define CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_KEY_UTILITY_CLIENT_H_ |
| 7 #pragma once | 7 #pragma once |
| 8 | 8 |
| 9 #include "base/ref_counted.h" | 9 #include "base/ref_counted.h" |
| 10 #include "base/synchronization/lock.h" | |
| 10 #include "base/synchronization/waitable_event.h" | 11 #include "base/synchronization/waitable_event.h" |
| 11 #include "chrome/browser/utility_process_host.h" | 12 #include "chrome/browser/utility_process_host.h" |
| 12 | 13 |
| 13 class IndexedDBKey; | 14 class IndexedDBKey; |
| 14 class SerializedScriptValue; | 15 class SerializedScriptValue; |
| 15 | 16 |
| 16 // This class is responsible to obtain IndexedDBKeys from the | 17 // This class is responsible to obtain IndexedDBKeys from the |
| 17 // SerializedScriptValues given an IDBKeyPath. It uses UtilityProcess to do this | 18 // SerializedScriptValues given an IDBKeyPath. It uses UtilityProcess to do this |
| 18 // inside a sandbox (a V8 lock is required there). At this level, all methods | 19 // inside a sandbox (a V8 lock is required there). At this level, all methods |
| 19 // are synchronous as required by the caller. The public API is used on | 20 // are synchronous as required by the caller. The public API is used on |
| 20 // WEBKIT thread, but internally it moves around to UI and IO as needed. | 21 // WEBKIT thread, but internally it moves around to UI and IO as needed. |
| 21 class IndexedDBKeyUtilityClient | 22 class IndexedDBKeyUtilityClient |
| 22 : public base::RefCountedThreadSafe<IndexedDBKeyUtilityClient> { | 23 : public base::RefCountedThreadSafe<IndexedDBKeyUtilityClient> { |
| 23 public: | 24 public: |
| 24 IndexedDBKeyUtilityClient(); | |
| 25 | 25 |
| 26 // Starts the UtilityProcess. Must be called before any other method. | 26 // Get a pointer to the IndexedDBKeyUtilityClient instance. |
| 27 void StartUtilityProcess(); | 27 static IndexedDBKeyUtilityClient* Get(); |
| 28 | 28 |
| 29 // Ends the UtilityProcess. Must be called after StartUtilityProcess() and | 29 // Shut down the IndexedDBKeyUtilityClient if it was ever started. |
| 30 // before destruction. | 30 static void Shutdown(); |
| 31 // TODO(bulach): figure out an appropriate hook so that we can keep the | |
| 32 // UtilityProcess running for a longer period of time and avoid spinning it | |
| 33 // on every IDBObjectStore::Put call. | |
| 34 void EndUtilityProcess(); | |
| 35 | 31 |
| 36 // Synchronously obtain the |keys| from |values| for the given |key_path|. | 32 // Synchronously obtain the |keys| from |values| for the given |key_path|. |
| 37 void CreateIDBKeysFromSerializedValuesAndKeyPath( | 33 void CreateIDBKeysFromSerializedValuesAndKeyPath( |
| 38 const std::vector<SerializedScriptValue>& values, | 34 const std::vector<SerializedScriptValue>& values, |
| 39 const string16& key_path, | 35 const string16& key_path, |
| 40 std::vector<IndexedDBKey>* keys); | 36 std::vector<IndexedDBKey>* keys); |
| 41 | 37 |
| 42 private: | 38 private: |
| 43 class Client : public UtilityProcessHost::Client { | 39 class Client : public UtilityProcessHost::Client { |
| 44 public: | 40 public: |
| 45 explicit Client(IndexedDBKeyUtilityClient* parent); | 41 explicit Client(IndexedDBKeyUtilityClient* parent); |
| 46 | 42 |
| 47 // UtilityProcessHost::Client | 43 // UtilityProcessHost::Client |
| 48 virtual void OnProcessCrashed(int exit_code); | 44 virtual void OnProcessCrashed(int exit_code); |
| 49 virtual void OnIDBKeysFromValuesAndKeyPathSucceeded( | 45 virtual void OnIDBKeysFromValuesAndKeyPathSucceeded( |
| 50 int id, const std::vector<IndexedDBKey>& keys); | 46 int id, const std::vector<IndexedDBKey>& keys); |
| 51 virtual void OnIDBKeysFromValuesAndKeyPathFailed(int id); | 47 virtual void OnIDBKeysFromValuesAndKeyPathFailed(int id); |
| 52 | 48 |
| 53 private: | 49 private: |
| 54 IndexedDBKeyUtilityClient* parent_; | 50 IndexedDBKeyUtilityClient* parent_; |
| 55 | 51 |
| 56 DISALLOW_COPY_AND_ASSIGN(Client); | 52 DISALLOW_COPY_AND_ASSIGN(Client); |
| 57 }; | 53 }; |
| 58 | 54 |
| 59 friend class base::RefCountedThreadSafe<IndexedDBKeyUtilityClient>; | 55 friend class base::RefCountedThreadSafe<IndexedDBKeyUtilityClient>; |
| 56 IndexedDBKeyUtilityClient(); | |
| 60 ~IndexedDBKeyUtilityClient(); | 57 ~IndexedDBKeyUtilityClient(); |
| 61 | 58 |
| 59 // Lock to protect the instance_ member. | |
| 60 static base::Lock instantiation_lock_; | |
| 61 static scoped_refptr<IndexedDBKeyUtilityClient> instance_; | |
|
bulach
2011/01/14 17:55:08
iirc, it's not safe / advisable to have non-POD st
| |
| 62 | |
| 63 // Starts the UtilityProcess. Must be called before any other method. | |
| 64 void StartUtilityProcess(); | |
| 65 | |
| 62 void GetRDHAndStartUtilityProcess(); | 66 void GetRDHAndStartUtilityProcess(); |
| 63 void StartUtilityProcessInternal(ResourceDispatcherHost* rdh); | 67 void StartUtilityProcessInternal(ResourceDispatcherHost* rdh); |
| 64 void EndUtilityProcessInternal(); | 68 void EndUtilityProcessInternal(); |
| 65 void CallStartIDBKeyFromValueAndKeyPathFromIOThread( | 69 void CallStartIDBKeyFromValueAndKeyPathFromIOThread( |
| 66 const std::vector<SerializedScriptValue>& values, | 70 const std::vector<SerializedScriptValue>& values, |
| 67 const string16& key_path); | 71 const string16& key_path); |
| 68 | 72 |
| 69 void SetKeys(const std::vector<IndexedDBKey>& keys); | 73 void SetKeys(const std::vector<IndexedDBKey>& keys); |
| 70 void FinishCreatingKeys(); | 74 void FinishCreatingKeys(); |
| 71 | 75 |
| (...skipping 11 matching lines...) Expand all Loading... | |
| 83 std::vector<IndexedDBKey> keys_; | 87 std::vector<IndexedDBKey> keys_; |
| 84 | 88 |
| 85 // Used in the IO thread. | 89 // Used in the IO thread. |
| 86 UtilityProcessHost* utility_process_host_; | 90 UtilityProcessHost* utility_process_host_; |
| 87 scoped_refptr<Client> client_; | 91 scoped_refptr<Client> client_; |
| 88 | 92 |
| 89 DISALLOW_COPY_AND_ASSIGN(IndexedDBKeyUtilityClient); | 93 DISALLOW_COPY_AND_ASSIGN(IndexedDBKeyUtilityClient); |
| 90 }; | 94 }; |
| 91 | 95 |
| 92 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_KEY_UTILITY_CLIENT_H_ | 96 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_KEY_UTILITY_CLIENT_H_ |
| OLD | NEW |