forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create SendRegistrationPing in UpdateClient
Create a new state and event within the component type. Within the UpdateEngine and UpdateClient create SendRegistrationPing that calls for registration event to be sent. The execution path for the the registration ping is not taken by the code inside the component updater The change is needed for the code in //chrome/updater. Bug:1096733 Change-Id: I0f239d8d837eb22dda49165ae04698d896860578 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2290195 Reviewed-by: Tommy Li <tommycli@chromium.org> Reviewed-by: Sorin Jianu <sorin@chromium.org> Reviewed-by: Joshua Pawlicki <waffles@chromium.org> Commit-Queue: Samantha Sappenfield <t-sasap@microsoft.com> Cr-Commit-Position: refs/heads/master@{#792810}
- Loading branch information
Sam Sappenfield
authored and
Commit Bot
committed
Jul 29, 2020
1 parent
c516a78
commit 4a06526
Showing
17 changed files
with
369 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#include "components/update_client/task_send_registration_ping.h" | ||
|
||
#include <utility> | ||
|
||
#include "base/bind.h" | ||
#include "base/location.h" | ||
#include "base/threading/sequenced_task_runner_handle.h" | ||
#include "base/version.h" | ||
#include "components/update_client/update_client.h" | ||
#include "components/update_client/update_engine.h" | ||
|
||
namespace update_client { | ||
|
||
TaskSendRegistrationPing::TaskSendRegistrationPing( | ||
scoped_refptr<UpdateEngine> update_engine, | ||
const std::string& id, | ||
const base::Version& version, | ||
Callback callback) | ||
: update_engine_(update_engine), | ||
id_(id), | ||
version_(version), | ||
callback_(std::move(callback)) {} | ||
|
||
TaskSendRegistrationPing::~TaskSendRegistrationPing() { | ||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | ||
} | ||
|
||
void TaskSendRegistrationPing::Run() { | ||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | ||
|
||
if (id_.empty()) { | ||
TaskComplete(Error::INVALID_ARGUMENT); | ||
return; | ||
} | ||
|
||
update_engine_->SendRegistrationPing( | ||
id_, version_, | ||
base::BindOnce(&TaskSendRegistrationPing::TaskComplete, this)); | ||
} | ||
|
||
void TaskSendRegistrationPing::Cancel() { | ||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | ||
|
||
TaskComplete(Error::UPDATE_CANCELED); | ||
} | ||
|
||
std::vector<std::string> TaskSendRegistrationPing::GetIds() const { | ||
return std::vector<std::string>{id_}; | ||
} | ||
|
||
void TaskSendRegistrationPing::TaskComplete(Error error) { | ||
DCHECK_CALLED_ON_VALID_SEQUENCE(sequence_checker_); | ||
|
||
base::SequencedTaskRunnerHandle::Get()->PostTask( | ||
FROM_HERE, | ||
base::BindOnce(&TaskSendRegistrationPing::RunCallback, this, error)); | ||
} | ||
|
||
void TaskSendRegistrationPing::RunCallback(Error error) { | ||
std::move(callback_).Run(this, error); | ||
} | ||
|
||
} // namespace update_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2020 The Chromium Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
#ifndef COMPONENTS_UPDATE_CLIENT_TASK_SEND_REGISTRATION_PING_H_ | ||
#define COMPONENTS_UPDATE_CLIENT_TASK_SEND_REGISTRATION_PING_H_ | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "base/callback.h" | ||
#include "base/memory/ref_counted.h" | ||
#include "base/sequence_checker.h" | ||
#include "components/update_client/task.h" | ||
#include "components/update_client/update_client.h" | ||
|
||
namespace base { | ||
class Version; | ||
} | ||
|
||
namespace update_client { | ||
|
||
class UpdateEngine; | ||
enum class Error; | ||
|
||
// Defines a specialized task for sending the registration ping. | ||
class TaskSendRegistrationPing : public Task { | ||
public: | ||
using Callback = | ||
base::OnceCallback<void(scoped_refptr<Task> task, Error error)>; | ||
|
||
TaskSendRegistrationPing(const TaskSendRegistrationPing&) = delete; | ||
TaskSendRegistrationPing& operator=(const TaskSendRegistrationPing&) = delete; | ||
|
||
// |update_engine| is injected here to handle the task. | ||
// |id| represents the CRX to send the ping for. | ||
// |callback| is posted when the task is done. | ||
TaskSendRegistrationPing(scoped_refptr<UpdateEngine> update_engine, | ||
const std::string& id, | ||
const base::Version& version, | ||
Callback callback); | ||
|
||
void Run() override; | ||
|
||
void Cancel() override; | ||
|
||
std::vector<std::string> GetIds() const override; | ||
|
||
private: | ||
~TaskSendRegistrationPing() override; | ||
|
||
// Called when the task has completed either because the task has run or | ||
// it has been canceled. | ||
void TaskComplete(Error error); | ||
|
||
// Runs the task registration ping callback | ||
void RunCallback(Error error); | ||
|
||
SEQUENCE_CHECKER(sequence_checker_); | ||
scoped_refptr<UpdateEngine> update_engine_; | ||
const std::string id_; | ||
const base::Version version_; | ||
Callback callback_; | ||
}; | ||
|
||
} // namespace update_client | ||
|
||
#endif // COMPONENTS_UPDATE_CLIENT_TASK_SEND_REGISTRATION_PING_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.