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 <vector> | |
10 | |
9 #include "base/ref_counted.h" | 11 #include "base/ref_counted.h" |
10 #include "base/synchronization/waitable_event.h" | 12 #include "base/singleton.h" |
11 #include "chrome/browser/utility_process_host.h" | 13 #include "base/string16.h" |
12 | 14 |
13 class IndexedDBKey; | 15 class IndexedDBKey; |
14 class SerializedScriptValue; | 16 class SerializedScriptValue; |
17 class KeyUtilityClientImpl; | |
15 | 18 |
16 // This class is responsible to obtain IndexedDBKeys from the | 19 // Class for obtaining IndexedDBKeys from the SerializedScriptValues given |
17 // SerializedScriptValues given an IDBKeyPath. It uses UtilityProcess to do this | 20 // an IDBKeyPath. This class is a thin singleton wrapper around the |
18 // inside a sandbox (a V8 lock is required there). At this level, all methods | 21 // KeyUtilityClientImpl, which does the real work. |
19 // are synchronous as required by the caller. The public API is used on | 22 class IndexedDBKeyUtilityClient { |
20 // WEBKIT thread, but internally it moves around to UI and IO as needed. | |
21 class IndexedDBKeyUtilityClient | |
22 : public base::RefCountedThreadSafe<IndexedDBKeyUtilityClient> { | |
23 public: | 23 public: |
24 IndexedDBKeyUtilityClient(); | 24 // Returns the singleton instance of the IndexedDBKeyUtilityClient. |
25 static IndexedDBKeyUtilityClient* GetInstance(); | |
25 | 26 |
26 // Starts the UtilityProcess. Must be called before any other method. | 27 // Shut down the underlying implementation. |
bulach
2011/01/20 16:49:15
add a note about which thread this must be called?
hans
2011/01/20 17:24:59
Done.
| |
27 void StartUtilityProcess(); | 28 void Shutdown(); |
28 | |
29 // Ends the UtilityProcess. Must be called after StartUtilityProcess() and | |
30 // before destruction. | |
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 | 29 |
36 // Synchronously obtain the |keys| from |values| for the given |key_path|. | 30 // Synchronously obtain the |keys| from |values| for the given |key_path|. |
37 void CreateIDBKeysFromSerializedValuesAndKeyPath( | 31 void CreateIDBKeysFromSerializedValuesAndKeyPath( |
38 const std::vector<SerializedScriptValue>& values, | 32 const std::vector<SerializedScriptValue>& values, |
39 const string16& key_path, | 33 const string16& key_path, |
40 std::vector<IndexedDBKey>* keys); | 34 std::vector<IndexedDBKey>* keys); |
41 | 35 |
42 private: | 36 private: |
43 class Client : public UtilityProcessHost::Client { | 37 friend struct DefaultSingletonTraits<IndexedDBKeyUtilityClient>; |
44 public: | 38 IndexedDBKeyUtilityClient(); |
45 explicit Client(IndexedDBKeyUtilityClient* parent); | |
46 | |
47 // UtilityProcessHost::Client | |
48 virtual void OnProcessCrashed(int exit_code); | |
49 virtual void OnIDBKeysFromValuesAndKeyPathSucceeded( | |
50 int id, const std::vector<IndexedDBKey>& keys); | |
51 virtual void OnIDBKeysFromValuesAndKeyPathFailed(int id); | |
52 | |
53 private: | |
54 IndexedDBKeyUtilityClient* parent_; | |
55 | |
56 DISALLOW_COPY_AND_ASSIGN(Client); | |
57 }; | |
58 | |
59 friend class base::RefCountedThreadSafe<IndexedDBKeyUtilityClient>; | |
60 ~IndexedDBKeyUtilityClient(); | 39 ~IndexedDBKeyUtilityClient(); |
61 | 40 |
62 void GetRDHAndStartUtilityProcess(); | 41 // The real client; laziliy instantiated. |
bulach
2011/01/20 16:49:15
move the comment one down
hans
2011/01/20 17:24:59
Whoops. Done.
| |
63 void StartUtilityProcessInternal(ResourceDispatcherHost* rdh); | 42 bool is_shutdown_; |
64 void EndUtilityProcessInternal(); | 43 scoped_refptr<KeyUtilityClientImpl> impl_; |
65 void CallStartIDBKeyFromValueAndKeyPathFromIOThread( | |
66 const std::vector<SerializedScriptValue>& values, | |
67 const string16& key_path); | |
68 | |
69 void SetKeys(const std::vector<IndexedDBKey>& keys); | |
70 void FinishCreatingKeys(); | |
71 | |
72 base::WaitableEvent waitable_event_; | |
73 | |
74 // Used in both IO and WEBKIT threads, but guarded by WaitableEvent, i.e., | |
75 // these members are only set / read when the other thread is blocked. | |
76 enum State { | |
77 STATE_UNINITIALIZED, | |
78 STATE_INITIALIZED, | |
79 STATE_CREATING_KEYS, | |
80 STATE_SHUTDOWN, | |
81 }; | |
82 State state_; | |
83 std::vector<IndexedDBKey> keys_; | |
84 | |
85 // Used in the IO thread. | |
86 UtilityProcessHost* utility_process_host_; | |
87 scoped_refptr<Client> client_; | |
88 | |
89 DISALLOW_COPY_AND_ASSIGN(IndexedDBKeyUtilityClient); | |
90 }; | 44 }; |
91 | 45 |
92 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_KEY_UTILITY_CLIENT_H_ | 46 #endif // CHROME_BROWSER_IN_PROCESS_WEBKIT_INDEXED_DB_KEY_UTILITY_CLIENT_H_ |
OLD | NEW |