Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(150)

Side by Side Diff: chrome/browser/extensions/api/notifications/notifications_api.cc

Issue 855813002: Mark create/update/clear callbacks of notification API as optional (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: comments #25 Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | chrome/common/extensions/api/notifications.idl » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « no previous file | chrome/common/extensions/api/notifications.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698