| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/api/runtime/runtime_api.h" | 5 #include "extensions/browser/api/runtime/runtime_api.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
| 11 #include "base/location.h" |
| 11 #include "base/logging.h" | 12 #include "base/logging.h" |
| 12 #include "base/memory/ptr_util.h" | 13 #include "base/memory/ptr_util.h" |
| 13 #include "base/metrics/histogram.h" | 14 #include "base/metrics/histogram.h" |
| 15 #include "base/single_thread_task_runner.h" |
| 16 #include "base/threading/thread_task_runner_handle.h" |
| 14 #include "base/values.h" | 17 #include "base/values.h" |
| 15 #include "base/version.h" | 18 #include "base/version.h" |
| 16 #include "content/public/browser/browser_context.h" | 19 #include "content/public/browser/browser_context.h" |
| 17 #include "content/public/browser/child_process_security_policy.h" | 20 #include "content/public/browser/child_process_security_policy.h" |
| 18 #include "content/public/browser/notification_service.h" | 21 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/browser/render_frame_host.h" | 22 #include "content/public/browser/render_frame_host.h" |
| 20 #include "content/public/browser/render_process_host.h" | 23 #include "content/public/browser/render_process_host.h" |
| 21 #include "extensions/browser/api/runtime/runtime_api_delegate.h" | 24 #include "extensions/browser/api/runtime/runtime_api_delegate.h" |
| 22 #include "extensions/browser/event_router.h" | 25 #include "extensions/browser/event_router.h" |
| 23 #include "extensions/browser/extension_host.h" | 26 #include "extensions/browser/extension_host.h" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 // We're done restarting Chrome after an update. | 190 // We're done restarting Chrome after an update. |
| 188 dispatch_chrome_updated_event_ = false; | 191 dispatch_chrome_updated_event_ = false; |
| 189 | 192 |
| 190 delegate_->AddUpdateObserver(this); | 193 delegate_->AddUpdateObserver(this); |
| 191 } | 194 } |
| 192 | 195 |
| 193 void RuntimeAPI::OnExtensionLoaded(content::BrowserContext* browser_context, | 196 void RuntimeAPI::OnExtensionLoaded(content::BrowserContext* browser_context, |
| 194 const Extension* extension) { | 197 const Extension* extension) { |
| 195 base::Version previous_version; | 198 base::Version previous_version; |
| 196 if (ReadPendingOnInstallInfoFromPref(extension->id(), &previous_version)) { | 199 if (ReadPendingOnInstallInfoFromPref(extension->id(), &previous_version)) { |
| 197 base::MessageLoop::current()->PostTask( | 200 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 198 FROM_HERE, | 201 FROM_HERE, |
| 199 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, | 202 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, |
| 200 browser_context_, extension->id(), previous_version, false)); | 203 browser_context_, extension->id(), previous_version, false)); |
| 201 RemovePendingOnInstallInfoFromPref(extension->id()); | 204 RemovePendingOnInstallInfoFromPref(extension->id()); |
| 202 } | 205 } |
| 203 | 206 |
| 204 if (!dispatch_chrome_updated_event_) | 207 if (!dispatch_chrome_updated_event_) |
| 205 return; | 208 return; |
| 206 | 209 |
| 207 // Dispatch the onInstalled event with reason "chrome_update". | 210 // Dispatch the onInstalled event with reason "chrome_update". |
| 208 base::MessageLoop::current()->PostTask( | 211 base::ThreadTaskRunnerHandle::Get()->PostTask( |
| 209 FROM_HERE, | 212 FROM_HERE, |
| 210 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, | 213 base::Bind(&RuntimeEventRouter::DispatchOnInstalledEvent, |
| 211 browser_context_, | 214 browser_context_, extension->id(), Version(), true)); |
| 212 extension->id(), | |
| 213 Version(), | |
| 214 true)); | |
| 215 } | 215 } |
| 216 | 216 |
| 217 void RuntimeAPI::OnExtensionWillBeInstalled( | 217 void RuntimeAPI::OnExtensionWillBeInstalled( |
| 218 content::BrowserContext* browser_context, | 218 content::BrowserContext* browser_context, |
| 219 const Extension* extension, | 219 const Extension* extension, |
| 220 bool is_update, | 220 bool is_update, |
| 221 const std::string& old_name) { | 221 const std::string& old_name) { |
| 222 // This extension might be disabled before it has a chance to load, e.g. if | 222 // This extension might be disabled before it has a chance to load, e.g. if |
| 223 // the extension increased its permissions. So instead of trying to send the | 223 // the extension increased its permissions. So instead of trying to send the |
| 224 // onInstalled event here, we remember the fact in prefs and fire the event | 224 // onInstalled event here, we remember the fact in prefs and fire the event |
| (...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 579 content::ChildProcessSecurityPolicy* policy = | 579 content::ChildProcessSecurityPolicy* policy = |
| 580 content::ChildProcessSecurityPolicy::GetInstance(); | 580 content::ChildProcessSecurityPolicy::GetInstance(); |
| 581 policy->GrantReadFileSystem(renderer_id, filesystem_id); | 581 policy->GrantReadFileSystem(renderer_id, filesystem_id); |
| 582 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); | 582 std::unique_ptr<base::DictionaryValue> dict(new base::DictionaryValue()); |
| 583 dict->SetString("fileSystemId", filesystem_id); | 583 dict->SetString("fileSystemId", filesystem_id); |
| 584 dict->SetString("baseName", relative_path); | 584 dict->SetString("baseName", relative_path); |
| 585 return RespondNow(OneArgument(std::move(dict))); | 585 return RespondNow(OneArgument(std::move(dict))); |
| 586 } | 586 } |
| 587 | 587 |
| 588 } // namespace extensions | 588 } // namespace extensions |
| OLD | NEW |