| 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/notifications/notifications_api.h" | 5 #include "chrome/browser/extensions/api/notifications/notifications_api.h" |
| 6 | 6 |
| 7 #include "base/callback.h" | 7 #include "base/callback.h" |
| 8 #include "base/guid.h" | 8 #include "base/guid.h" |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 170 return scoped_id_; | 170 return scoped_id_; |
| 171 } | 171 } |
| 172 | 172 |
| 173 virtual int process_id() const OVERRIDE { | 173 virtual int process_id() const OVERRIDE { |
| 174 return process_id_; | 174 return process_id_; |
| 175 } | 175 } |
| 176 | 176 |
| 177 virtual content::WebContents* GetWebContents() const OVERRIDE { | 177 virtual content::WebContents* GetWebContents() const OVERRIDE { |
| 178 // We're holding a reference to api_function_, so we know it'll be valid | 178 // We're holding a reference to api_function_, so we know it'll be valid |
| 179 // until ReleaseRVH is called, and api_function_ (as a | 179 // until ReleaseRVH is called, and api_function_ (as a |
| 180 // UIThreadExtensionFunction) will zero out its copy of render_view_host | 180 // AsyncExtensionFunction) will zero out its copy of render_view_host |
| 181 // when the RVH goes away. | 181 // when the RVH goes away. |
| 182 if (!api_function_.get()) | 182 if (!api_function_.get()) |
| 183 return NULL; | 183 return NULL; |
| 184 content::RenderViewHost* rvh = api_function_->render_view_host(); | 184 content::RenderViewHost* rvh = api_function_->render_view_host(); |
| 185 if (!rvh) | 185 if (!rvh) |
| 186 return NULL; | 186 return NULL; |
| 187 return content::WebContents::FromRenderViewHost(rvh); | 187 return content::WebContents::FromRenderViewHost(rvh); |
| 188 } | 188 } |
| 189 | 189 |
| 190 virtual void ReleaseRenderViewHost() OVERRIDE { | 190 virtual void ReleaseRenderViewHost() OVERRIDE { |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 } | 444 } |
| 445 | 445 |
| 446 bool NotificationsApiFunction::IsNotificationsApiEnabled() const { | 446 bool NotificationsApiFunction::IsNotificationsApiEnabled() const { |
| 447 return CanRunWhileDisabled() || AreExtensionNotificationsAllowed(); | 447 return CanRunWhileDisabled() || AreExtensionNotificationsAllowed(); |
| 448 } | 448 } |
| 449 | 449 |
| 450 bool NotificationsApiFunction::CanRunWhileDisabled() const { | 450 bool NotificationsApiFunction::CanRunWhileDisabled() const { |
| 451 return false; | 451 return false; |
| 452 } | 452 } |
| 453 | 453 |
| 454 bool NotificationsApiFunction::RunImpl() { | 454 bool NotificationsApiFunction::RunAsync() { |
| 455 if (IsNotificationsApiAvailable() && IsNotificationsApiEnabled()) { | 455 if (IsNotificationsApiAvailable() && IsNotificationsApiEnabled()) { |
| 456 return RunNotificationsApi(); | 456 return RunNotificationsApi(); |
| 457 } else { | 457 } else { |
| 458 SendResponse(false); | 458 SendResponse(false); |
| 459 return true; | 459 return true; |
| 460 } | 460 } |
| 461 } | 461 } |
| 462 | 462 |
| 463 message_center::NotificationType | 463 message_center::NotificationType |
| 464 NotificationsApiFunction::MapApiTemplateTypeToType( | 464 NotificationsApiFunction::MapApiTemplateTypeToType( |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 614 ? api::notifications::PERMISSION_LEVEL_GRANTED | 614 ? api::notifications::PERMISSION_LEVEL_GRANTED |
| 615 : api::notifications::PERMISSION_LEVEL_DENIED; | 615 : api::notifications::PERMISSION_LEVEL_DENIED; |
| 616 | 616 |
| 617 SetResult(new base::StringValue(api::notifications::ToString(result))); | 617 SetResult(new base::StringValue(api::notifications::ToString(result))); |
| 618 SendResponse(true); | 618 SendResponse(true); |
| 619 | 619 |
| 620 return true; | 620 return true; |
| 621 } | 621 } |
| 622 | 622 |
| 623 } // namespace extensions | 623 } // namespace extensions |
| OLD | NEW |