| 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/extensions/api/api_function.h" | 5 #include "chrome/browser/extensions/api/api_function.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "chrome/browser/extensions/api/api_resource_controller.h" | 8 #include "chrome/browser/extensions/api/api_resource_controller.h" |
| 9 #include "chrome/browser/extensions/api/api_resource_event_notifier.h" | 9 #include "chrome/browser/extensions/api/api_resource_event_notifier.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/profiles/profile.h" | 11 #include "chrome/browser/profiles/profile.h" |
| 12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
| 13 | 13 |
| 14 using content::BrowserThread; | 14 using content::BrowserThread; |
| 15 | 15 |
| 16 namespace extensions { | 16 namespace extensions { |
| 17 | 17 |
| 18 bool AsyncIOAPIFunction::RunImpl() { | |
| 19 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 20 extension_service_ = profile()->GetExtensionService(); | |
| 21 | |
| 22 if (!Prepare()) { | |
| 23 return false; | |
| 24 } | |
| 25 bool rv = BrowserThread::PostTask( | |
| 26 BrowserThread::IO, FROM_HERE, | |
| 27 base::Bind(&AsyncIOAPIFunction::WorkOnIOThread, this)); | |
| 28 DCHECK(rv); | |
| 29 return true; | |
| 30 } | |
| 31 | |
| 32 void AsyncIOAPIFunction::WorkOnIOThread() { | |
| 33 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
| 34 Work(); | |
| 35 bool rv = BrowserThread::PostTask( | |
| 36 BrowserThread::UI, FROM_HERE, | |
| 37 base::Bind(&AsyncIOAPIFunction::RespondOnUIThread, this)); | |
| 38 DCHECK(rv); | |
| 39 } | |
| 40 | |
| 41 void AsyncIOAPIFunction::RespondOnUIThread() { | |
| 42 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | |
| 43 SendResponse(Respond()); | |
| 44 } | |
| 45 | |
| 46 int AsyncIOAPIFunction::ExtractSrcId(size_t argument_position) { | 18 int AsyncIOAPIFunction::ExtractSrcId(size_t argument_position) { |
| 47 scoped_ptr<DictionaryValue> options(new DictionaryValue()); | 19 scoped_ptr<DictionaryValue> options(new DictionaryValue()); |
| 48 if (args_->GetSize() > argument_position) { | 20 if (args_->GetSize() > argument_position) { |
| 49 DictionaryValue* temp_options = NULL; | 21 DictionaryValue* temp_options = NULL; |
| 50 if (args_->GetDictionary(argument_position, &temp_options)) | 22 if (args_->GetDictionary(argument_position, &temp_options)) |
| 51 options.reset(temp_options->DeepCopy()); | 23 options.reset(temp_options->DeepCopy()); |
| 52 } | 24 } |
| 53 | 25 |
| 54 // If we tacked on a srcId to the options object, pull it out here to provide | 26 // If we tacked on a srcId to the options object, pull it out here to provide |
| 55 // to the Socket. | 27 // to the Socket. |
| (...skipping 12 matching lines...) Expand all Loading... |
| 68 src_id, source_url()); | 40 src_id, source_url()); |
| 69 } | 41 } |
| 70 | 42 |
| 71 APIResourceController* AsyncIOAPIFunction::controller() { | 43 APIResourceController* AsyncIOAPIFunction::controller() { |
| 72 // ExtensionService's APIResourceController is set exactly once, long before | 44 // ExtensionService's APIResourceController is set exactly once, long before |
| 73 // this code is reached, so it's safe to access it on either the IO or UI | 45 // this code is reached, so it's safe to access it on either the IO or UI |
| 74 // thread. | 46 // thread. |
| 75 return extension_service_->api_resource_controller(); | 47 return extension_service_->api_resource_controller(); |
| 76 } | 48 } |
| 77 | 49 |
| 50 bool AsyncIOAPIFunction::RunImpl() { |
| 51 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 52 extension_service_ = profile()->GetExtensionService(); |
| 53 |
| 54 if (!Prepare()) { |
| 55 return false; |
| 56 } |
| 57 bool rv = BrowserThread::PostTask( |
| 58 BrowserThread::IO, FROM_HERE, |
| 59 base::Bind(&AsyncIOAPIFunction::WorkOnIOThread, this)); |
| 60 DCHECK(rv); |
| 61 return true; |
| 62 } |
| 63 |
| 64 void AsyncIOAPIFunction::WorkOnIOThread() { |
| 65 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 66 Work(); |
| 67 bool rv = BrowserThread::PostTask( |
| 68 BrowserThread::UI, FROM_HERE, |
| 69 base::Bind(&AsyncIOAPIFunction::RespondOnUIThread, this)); |
| 70 DCHECK(rv); |
| 71 } |
| 72 |
| 73 void AsyncIOAPIFunction::RespondOnUIThread() { |
| 74 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 75 SendResponse(Respond()); |
| 76 } |
| 77 |
| 78 } // namespace extensions | 78 } // namespace extensions |
| OLD | NEW |