Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: chrome/browser/utility_process_host.h

Issue 3043037: Adds IDBKeyPath parser / extractor, and provides a mechanism to call it sandboxed. (Closed)
Patch Set: Makes MSVC happy. Created 10 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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_UTILITY_PROCESS_HOST_H_ 5 #ifndef CHROME_BROWSER_UTILITY_PROCESS_HOST_H_
6 #define CHROME_BROWSER_UTILITY_PROCESS_HOST_H_ 6 #define CHROME_BROWSER_UTILITY_PROCESS_HOST_H_
7 #pragma once 7 #pragma once
8 8
9 #include <string> 9 #include <string>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/basictypes.h" 12 #include "base/basictypes.h"
13 #include "base/ref_counted.h" 13 #include "base/ref_counted.h"
14 #include "base/task.h" 14 #include "base/task.h"
15 #include "chrome/browser/browser_child_process_host.h" 15 #include "chrome/browser/browser_child_process_host.h"
16 #include "chrome/browser/chrome_thread.h" 16 #include "chrome/browser/chrome_thread.h"
17 #include "chrome/common/extensions/update_manifest.h" 17 #include "chrome/common/extensions/update_manifest.h"
18 #include "ipc/ipc_channel.h" 18 #include "ipc/ipc_channel.h"
19 19
20 class DictionaryValue; 20 class DictionaryValue;
21 class IndexedDBKey;
22 class SerializedScriptValue;
21 class SkBitmap; 23 class SkBitmap;
22 24
23 // This class acts as the browser-side host to a utility child process. A 25 // This class acts as the browser-side host to a utility child process. A
24 // utility process is a short-lived sandboxed process that is created to run 26 // utility process is a short-lived sandboxed process that is created to run
25 // a specific task. This class lives solely on the IO thread. 27 // a specific task. This class lives solely on the IO thread.
28 // If you need a single method call in the sandbox, use StartFooBar(p).
29 // If you need multiple batches of work to be done in the sandboxed process,
30 // use StartBatchMode(), then multiple calls to StartFooBar(p),
31 // then finish with EndBatchMode().
26 class UtilityProcessHost : public BrowserChildProcessHost { 32 class UtilityProcessHost : public BrowserChildProcessHost {
27 public: 33 public:
28 // An interface to be implemented by consumers of the utility process to 34 // An interface to be implemented by consumers of the utility process to
29 // get results back. All functions are called on the thread passed along 35 // get results back. All functions are called on the thread passed along
30 // to UtilityProcessHost. 36 // to UtilityProcessHost.
31 class Client : public base::RefCountedThreadSafe<Client> { 37 class Client : public base::RefCountedThreadSafe<Client> {
32 public: 38 public:
33 Client() {} 39 Client() {}
34 40
35 // Called when the process has crashed. 41 // Called when the process has crashed.
(...skipping 29 matching lines...) Expand all
65 const std::string& error_message) {} 71 const std::string& error_message) {}
66 72
67 // Called when image data was successfully decoded. |decoded_image| 73 // Called when image data was successfully decoded. |decoded_image|
68 // stores the result. 74 // stores the result.
69 virtual void OnDecodeImageSucceeded( 75 virtual void OnDecodeImageSucceeded(
70 const SkBitmap& decoded_image) {} 76 const SkBitmap& decoded_image) {}
71 77
72 // Called when image data decoding failed. 78 // Called when image data decoding failed.
73 virtual void OnDecodeImageFailed() {} 79 virtual void OnDecodeImageFailed() {}
74 80
81 // Called when we have successfully obtained the IndexedDBKey after
82 // a call to StartIDBKeysFromValuesAndKeyPath.
83 // |id| is the corresponding identifier.
84 // |keys| the corresponding IndexedDBKey.
85 virtual void OnIDBKeysFromValuesAndKeyPathSucceeded(
86 int id, const std::vector<IndexedDBKey>& keys) {}
87
88 // Called when IDBKeyPath has failed.
89 // |id| is the corresponding identifier passed on
90 // StartIDBKeysFromValuesAndKeyPath.
91 virtual void OnIDBKeysFromValuesAndKeyPathFailed(int id) {}
92
75 protected: 93 protected:
76 friend class base::RefCountedThreadSafe<Client>; 94 friend class base::RefCountedThreadSafe<Client>;
77 95
78 virtual ~Client() {} 96 virtual ~Client() {}
79 97
80 private: 98 private:
81 friend class UtilityProcessHost; 99 friend class UtilityProcessHost;
82 100
83 void OnMessageReceived(const IPC::Message& message); 101 void OnMessageReceived(const IPC::Message& message);
84 102
(...skipping 17 matching lines...) Expand all
102 // doesn't do any unpacking. This should change once we finalize the 120 // doesn't do any unpacking. This should change once we finalize the
103 // web resource server format(s). 121 // web resource server format(s).
104 bool StartWebResourceUnpacker(const std::string& data); 122 bool StartWebResourceUnpacker(const std::string& data);
105 123
106 // Start parsing an extensions auto-update manifest xml file. 124 // Start parsing an extensions auto-update manifest xml file.
107 bool StartUpdateManifestParse(const std::string& xml); 125 bool StartUpdateManifestParse(const std::string& xml);
108 126
109 // Start image decoding. 127 // Start image decoding.
110 bool StartImageDecoding(const std::vector<unsigned char>& encoded_data); 128 bool StartImageDecoding(const std::vector<unsigned char>& encoded_data);
111 129
130 // Starts extracting |key_path| from |serialized_values|, and replies with the
131 // corresponding IndexedDBKeys via OnIDBKeysFromValuesAndKeyPathSucceeded.
132 bool StartIDBKeysFromValuesAndKeyPath(
133 int id, const std::vector<SerializedScriptValue>& serialized_values,
134 const string16& key_path);
135
136 // Starts utility process in batch mode. Caller must call EndBatchMode()
137 // to finish the utility process.
138 bool StartBatchMode();
139
140 // Ends the utility process. Must be called after StartBatchMode().
141 void EndBatchMode();
142
112 protected: 143 protected:
113 // Allow these methods to be overridden for tests. 144 // Allow these methods to be overridden for tests.
114 virtual FilePath GetUtilityProcessCmd(); 145 virtual FilePath GetUtilityProcessCmd();
115 146
116 private: 147 private:
117 // Starts a process. Returns true iff it succeeded. 148 // Starts a process if necessary. Returns true if it succeeded or a process
149 // has already been started via StartBatchMode().
118 bool StartProcess(const FilePath& exposed_dir); 150 bool StartProcess(const FilePath& exposed_dir);
119 151
120 // IPC messages: 152 // IPC messages:
121 void OnMessageReceived(const IPC::Message& message); 153 void OnMessageReceived(const IPC::Message& message);
122 154
123 // BrowserChildProcessHost: 155 // BrowserChildProcessHost:
124 virtual void OnProcessCrashed(); 156 virtual void OnProcessCrashed();
125 virtual bool CanShutdown() { return true; } 157 virtual bool CanShutdown() { return true; }
126 virtual URLRequestContext* GetRequestContext( 158 virtual URLRequestContext* GetRequestContext(
127 uint32 request_id, 159 uint32 request_id,
128 const ViewHostMsg_Resource_Request& request_data) { 160 const ViewHostMsg_Resource_Request& request_data) {
129 return NULL; 161 return NULL;
130 } 162 }
131 163
132 // A pointer to our client interface, who will be informed of progress. 164 // A pointer to our client interface, who will be informed of progress.
133 scoped_refptr<Client> client_; 165 scoped_refptr<Client> client_;
134 ChromeThread::ID client_thread_id_; 166 ChromeThread::ID client_thread_id_;
167 // True when running in batch mode, i.e., StartBatchMode() has been called
168 // and the utility process will run until EndBatchMode().
169 bool is_batch_mode_;
135 170
136 DISALLOW_COPY_AND_ASSIGN(UtilityProcessHost); 171 DISALLOW_COPY_AND_ASSIGN(UtilityProcessHost);
137 }; 172 };
138 173
139 #endif // CHROME_BROWSER_UTILITY_PROCESS_HOST_H_ 174 #endif // CHROME_BROWSER_UTILITY_PROCESS_HOST_H_
OLDNEW
« no previous file with comments | « chrome/browser/idbbindingutilities_browsertest.cc ('k') | chrome/browser/utility_process_host.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698