OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 #include "chrome/browser/web_resource/json_asynchronous_unpacker.h" | 5 #include "chrome/browser/web_resource/json_asynchronous_unpacker.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "chrome/browser/web_resource/web_resource_service.h" | 8 #include "chrome/browser/web_resource/web_resource_service.h" |
9 #include "chrome/common/chrome_switches.h" | 9 #include "chrome/common/chrome_switches.h" |
10 #include "chrome/common/chrome_utility_messages.h" | 10 #include "chrome/common/chrome_utility_messages.h" |
(...skipping 11 matching lines...) Expand all Loading... |
22 class JSONAsynchronousUnpackerImpl | 22 class JSONAsynchronousUnpackerImpl |
23 : public UtilityProcessHostClient, | 23 : public UtilityProcessHostClient, |
24 public JSONAsynchronousUnpacker { | 24 public JSONAsynchronousUnpacker { |
25 public: | 25 public: |
26 explicit JSONAsynchronousUnpackerImpl( | 26 explicit JSONAsynchronousUnpackerImpl( |
27 JSONAsynchronousUnpackerDelegate* delegate) | 27 JSONAsynchronousUnpackerDelegate* delegate) |
28 : JSONAsynchronousUnpacker(delegate), | 28 : JSONAsynchronousUnpacker(delegate), |
29 got_response_(false) { | 29 got_response_(false) { |
30 } | 30 } |
31 | 31 |
32 virtual void Start(const std::string& json_data) OVERRIDE { | 32 virtual void Start(const std::string& json_data) override { |
33 AddRef(); // balanced in Cleanup. | 33 AddRef(); // balanced in Cleanup. |
34 | 34 |
35 BrowserThread::ID thread_id; | 35 BrowserThread::ID thread_id; |
36 CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_id)); | 36 CHECK(BrowserThread::GetCurrentThreadIdentifier(&thread_id)); |
37 BrowserThread::PostTask( | 37 BrowserThread::PostTask( |
38 BrowserThread::IO, FROM_HERE, | 38 BrowserThread::IO, FROM_HERE, |
39 base::Bind( | 39 base::Bind( |
40 &JSONAsynchronousUnpackerImpl::StartProcessOnIOThread, | 40 &JSONAsynchronousUnpackerImpl::StartProcessOnIOThread, |
41 this, thread_id, json_data)); | 41 this, thread_id, json_data)); |
42 } | 42 } |
43 | 43 |
44 private: | 44 private: |
45 virtual ~JSONAsynchronousUnpackerImpl() {} | 45 virtual ~JSONAsynchronousUnpackerImpl() {} |
46 | 46 |
47 // UtilityProcessHostClient. | 47 // UtilityProcessHostClient. |
48 virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE { | 48 virtual bool OnMessageReceived(const IPC::Message& message) override { |
49 bool handled = true; | 49 bool handled = true; |
50 IPC_BEGIN_MESSAGE_MAP(JSONAsynchronousUnpackerImpl, message) | 50 IPC_BEGIN_MESSAGE_MAP(JSONAsynchronousUnpackerImpl, message) |
51 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_UnpackWebResource_Succeeded, | 51 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_UnpackWebResource_Succeeded, |
52 OnUnpackWebResourceSucceeded) | 52 OnUnpackWebResourceSucceeded) |
53 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_UnpackWebResource_Failed, | 53 IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_UnpackWebResource_Failed, |
54 OnUnpackWebResourceFailed) | 54 OnUnpackWebResourceFailed) |
55 IPC_MESSAGE_UNHANDLED(handled = false) | 55 IPC_MESSAGE_UNHANDLED(handled = false) |
56 IPC_END_MESSAGE_MAP() | 56 IPC_END_MESSAGE_MAP() |
57 return handled; | 57 return handled; |
58 } | 58 } |
59 | 59 |
60 virtual void OnProcessCrashed(int exit_code) OVERRIDE { | 60 virtual void OnProcessCrashed(int exit_code) override { |
61 if (got_response_) | 61 if (got_response_) |
62 return; | 62 return; |
63 | 63 |
64 OnUnpackWebResourceFailed( | 64 OnUnpackWebResourceFailed( |
65 "Utility process crashed while trying to retrieve web resources."); | 65 "Utility process crashed while trying to retrieve web resources."); |
66 } | 66 } |
67 | 67 |
68 void OnUnpackWebResourceSucceeded( | 68 void OnUnpackWebResourceSucceeded( |
69 const base::DictionaryValue& parsed_json) { | 69 const base::DictionaryValue& parsed_json) { |
70 if (delegate_) | 70 if (delegate_) |
(...skipping 26 matching lines...) Expand all Loading... |
97 // True if we got a response from the utility process and have cleaned up | 97 // True if we got a response from the utility process and have cleaned up |
98 // already. | 98 // already. |
99 bool got_response_; | 99 bool got_response_; |
100 }; | 100 }; |
101 | 101 |
102 JSONAsynchronousUnpacker* JSONAsynchronousUnpacker::Create( | 102 JSONAsynchronousUnpacker* JSONAsynchronousUnpacker::Create( |
103 JSONAsynchronousUnpackerDelegate* delegate) { | 103 JSONAsynchronousUnpackerDelegate* delegate) { |
104 return new JSONAsynchronousUnpackerImpl(delegate); | 104 return new JSONAsynchronousUnpackerImpl(delegate); |
105 } | 105 } |
106 | 106 |
OLD | NEW |