Chromium Code Reviews| Index: components/policy/core/common/remote_commands/remote_commands_service.h |
| diff --git a/components/policy/core/common/remote_commands/remote_commands_service.h b/components/policy/core/common/remote_commands/remote_commands_service.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..fde30073e4c6ec213c5525a945e58a35bb3c76df |
| --- /dev/null |
| +++ b/components/policy/core/common/remote_commands/remote_commands_service.h |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2015 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_POLICY_CORE_COMMON_REMOTE_COMMANDS_REMOTE_COMMANDS_SERVICE_H_ |
| +#define COMPONENTS_POLICY_CORE_COMMON_REMOTE_COMMANDS_REMOTE_COMMANDS_SERVICE_H_ |
| + |
| +#include <vector> |
| + |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "base/memory/weak_ptr.h" |
| +#include "components/policy/core/common/remote_commands/remote_command_job.h" |
| +#include "components/policy/core/common/remote_commands/remote_commands_queue.h" |
| +#include "components/policy/policy_export.h" |
| +#include "policy/proto/device_management_backend.pb.h" |
| + |
| +namespace policy { |
| + |
| +class CloudPolicyClient; |
| +class RemoteCommandsFactory; |
| + |
| +// Service class which will connect to a CloudPolicyClient in order to fetch |
| +// remote commands from DMServer and send results for executed commands |
| +// back to server. |
| +class POLICY_EXPORT RemoteCommandsService |
| + : public RemoteCommandsQueue::Observer { |
| + public: |
| + RemoteCommandsService(scoped_ptr<RemoteCommandsFactory> factory, |
| + CloudPolicyClient* client); |
| + ~RemoteCommandsService() override; |
| + |
| + // Attempts to fetch remote commands, mainly supposed to be called by |
| + // invalidation service. Note that there will be at most one ongoing fetch |
| + // request and all other fetch request will be ignored if a fetch request is |
| + // in-progress. Returns true if a new command fetch request is created. |
|
bartfab (slow)
2015/02/18 11:12:53
You are not actually ignoring further fetch reques
binjin
2015/02/18 15:37:50
1. Recent changes (to allow multiple non-policy-fe
|
| + bool FetchRemoteCommands(); |
| + |
| + // Returns whether a command fetch request is in progress or not. |
| + bool IsCommandFetchInProgressForTesting() const { |
| + return command_fetch_in_progress_; |
| + } |
| + |
| + private: |
| + // Helper function to add an command which we get from server. |
| + void AddCommand(const enterprise_management::RemoteCommand& command); |
| + |
| + // RemoteCommandsQueue::Observer: |
| + void OnJobStarted(RemoteCommandJob* command) override; |
| + void OnJobFinished(RemoteCommandJob* command) override; |
| + |
| + // Callback to handle commands we get from server. |
| + void OnRemoteCommandsFetched( |
| + const std::vector<enterprise_management::RemoteCommand>& commands); |
| + |
| + bool command_fetch_in_progress_ = false; |
| + bool has_unhanded_fetch_request_ = false; |
|
bartfab (slow)
2015/02/18 11:12:53
Nit 1: s/unhanded/unhandled/
Nit 2: How about s/un
binjin
2015/02/18 15:37:50
Done.
|
| + std::vector<enterprise_management::RemoteCommandResult> unsent_results_; |
| + |
| + RemoteCommandJob::UniqueIDType last_fetched_command_id_ = 0; |
| + RemoteCommandJob::UniqueIDType last_executed_command_id_ = 0; |
| + |
| + RemoteCommandsQueue queue_; |
| + scoped_ptr<RemoteCommandsFactory> factory_; |
| + CloudPolicyClient* client_; |
| + |
| + base::WeakPtrFactory<RemoteCommandsService> weak_factory_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(RemoteCommandsService); |
| +}; |
| + |
| +} // namespace policy |
| + |
| +#endif // COMPONENTS_POLICY_CORE_COMMON_REMOTE_COMMANDS_REMOTE_COMMANDS_SERVICE_H_ |