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 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 | 470 |
471 NotificationsCreateFunction::~NotificationsCreateFunction() { | 471 NotificationsCreateFunction::~NotificationsCreateFunction() { |
472 } | 472 } |
473 | 473 |
474 bool NotificationsCreateFunction::RunNotificationsApi() { | 474 bool NotificationsCreateFunction::RunNotificationsApi() { |
475 params_ = api::notifications::Create::Params::Create(*args_); | 475 params_ = api::notifications::Create::Params::Create(*args_); |
476 EXTENSION_FUNCTION_VALIDATE(params_.get()); | 476 EXTENSION_FUNCTION_VALIDATE(params_.get()); |
477 | 477 |
478 const std::string extension_id(extension_->id()); | 478 const std::string extension_id(extension_->id()); |
479 std::string notification_id; | 479 std::string notification_id; |
480 if (!params_->notification_id.empty()) { | 480 if (params_->notification_id.get() && !params_->notification_id->empty()) { |
481 // If the caller provided a notificationId, use that. | 481 // If the caller provided a notificationId, use that. |
482 notification_id = params_->notification_id; | 482 notification_id = *params_->notification_id; |
483 } else { | 483 } else { |
484 // Otherwise, use a randomly created GUID. In case that GenerateGUID returns | 484 // Otherwise, use a randomly created GUID. In case that GenerateGUID returns |
485 // the empty string, simply generate a random string. | 485 // the empty string, simply generate a random string. |
486 notification_id = base::GenerateGUID(); | 486 notification_id = base::GenerateGUID(); |
487 if (notification_id.empty()) | 487 if (notification_id.empty()) |
488 notification_id = base::RandBytesAsString(16); | 488 notification_id = base::RandBytesAsString(16); |
489 } | 489 } |
490 | 490 |
491 SetResult(new base::StringValue(notification_id)); | 491 SetResult(new base::StringValue(notification_id)); |
492 | 492 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
601 ? api::notifications::PERMISSION_LEVEL_GRANTED | 601 ? api::notifications::PERMISSION_LEVEL_GRANTED |
602 : api::notifications::PERMISSION_LEVEL_DENIED; | 602 : api::notifications::PERMISSION_LEVEL_DENIED; |
603 | 603 |
604 SetResult(new base::StringValue(api::notifications::ToString(result))); | 604 SetResult(new base::StringValue(api::notifications::ToString(result))); |
605 SendResponse(true); | 605 SendResponse(true); |
606 | 606 |
607 return true; | 607 return true; |
608 } | 608 } |
609 | 609 |
610 } // namespace extensions | 610 } // namespace extensions |
OLD | NEW |