Commit 28b2c257 authored by Zach Trudo's avatar Zach Trudo Committed by Commit Bot

Split out classes for reporting client

StorageModule and EncryptionModule are needed in the reporting client
interface.

TestStorageModule and TestEncryptionModule are needed in the
reporting client tests.

Bug: chromium:1078512
Change-Id: Ic96ce4b9a85724f7dee20f4576e54383d6bc3330
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2228984
Commit-Queue: Zach Trudo <zatrudo@google.com>
Reviewed-by: default avatarSergey Poromov <poromov@chromium.org>
Auto-Submit: Zach Trudo <zatrudo@google.com>
Cr-Commit-Position: refs/heads/master@{#775190}
parent ea7f792d
...@@ -1264,10 +1264,14 @@ static_library("browser") { ...@@ -1264,10 +1264,14 @@ static_library("browser") {
"policy/homepage_location_policy_handler.h", "policy/homepage_location_policy_handler.h",
"policy/javascript_policy_handler.cc", "policy/javascript_policy_handler.cc",
"policy/javascript_policy_handler.h", "policy/javascript_policy_handler.h",
"policy/messaging_layer/encryption/encryption_module.cc",
"policy/messaging_layer/encryption/encryption_module.h",
"policy/messaging_layer/public/report_queue.cc", "policy/messaging_layer/public/report_queue.cc",
"policy/messaging_layer/public/report_queue.h", "policy/messaging_layer/public/report_queue.h",
"policy/messaging_layer/public/report_queue_configuration.cc", "policy/messaging_layer/public/report_queue_configuration.cc",
"policy/messaging_layer/public/report_queue_configuration.h", "policy/messaging_layer/public/report_queue_configuration.h",
"policy/messaging_layer/storage/storage_module.cc",
"policy/messaging_layer/storage/storage_module.h",
"policy/messaging_layer/util/status.cc", "policy/messaging_layer/util/status.cc",
"policy/messaging_layer/util/status.h", "policy/messaging_layer/util/status.h",
"policy/messaging_layer/util/status_macros.h", "policy/messaging_layer/util/status_macros.h",
......
// 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 <string>
#include "chrome/browser/policy/messaging_layer/encryption/encryption_module.h"
#include "chrome/browser/policy/messaging_layer/util/status.h"
#include "chrome/browser/policy/messaging_layer/util/statusor.h"
namespace reporting {
// EncryptRecord will attempt to encrypt the provided |record|. On success the
// return value will contain the encrypted string.
StatusOr<std::string> EncryptionModule::EncryptRecord(
base::StringPiece record) const {
return Status(error::UNIMPLEMENTED, "EncryptRecord isn't implemented");
}
} // namespace reporting
// 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 CHROME_BROWSER_POLICY_MESSAGING_LAYER_ENCRYPTION_ENCRYPTION_MODULE_H_
#define CHROME_BROWSER_POLICY_MESSAGING_LAYER_ENCRYPTION_ENCRYPTION_MODULE_H_
#include <string>
#include "base/memory/ref_counted.h"
#include "base/strings/string_piece.h"
#include "chrome/browser/policy/messaging_layer/util/status.h"
#include "chrome/browser/policy/messaging_layer/util/statusor.h"
namespace reporting {
// TODO(b/153659559) Temporary EncryptionModule until the real one is ready.
class EncryptionModule : public base::RefCounted<EncryptionModule> {
public:
EncryptionModule() = default;
EncryptionModule(const EncryptionModule& other) = delete;
EncryptionModule& operator=(const EncryptionModule& other) = delete;
// EncryptRecord will attempt to encrypt the provided |record|. On success the
// return value will contain the encrypted string.
virtual StatusOr<std::string> EncryptRecord(base::StringPiece record) const;
protected:
virtual ~EncryptionModule() = default;
private:
friend base::RefCounted<EncryptionModule>;
};
} // namespace reporting
#endif // CHROME_BROWSER_POLICY_MESSAGING_LAYER_ENCRYPTION_ENCRYPTION_MODULE_H_
// 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 <string>
#include "chrome/browser/policy/messaging_layer/encryption/test_encryption_module.h"
#include "chrome/browser/policy/messaging_layer/util/statusor.h"
namespace reporting {
namespace test {
StatusOr<std::string> TestEncryptionModule::EncryptRecord(
base::StringPiece record) const {
return std::string(record);
}
StatusOr<std::string> AlwaysFailsEncryptionModule::EncryptRecord(
base::StringPiece record) const {
return Status(error::UNKNOWN, "Failing for tests");
}
} // namespace test
} // namespace reporting
// 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 CHROME_BROWSER_POLICY_MESSAGING_LAYER_ENCRYPTION_TEST_ENCRYPTION_MODULE_H_
#define CHROME_BROWSER_POLICY_MESSAGING_LAYER_ENCRYPTION_TEST_ENCRYPTION_MODULE_H_
#include <string>
#include "chrome/browser/policy/messaging_layer/public/report_queue.h"
#include "chrome/browser/policy/messaging_layer/util/statusor.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace reporting {
namespace test {
// An |EncryptionModule| that does no encryption.
class TestEncryptionModule : public EncryptionModule {
public:
TestEncryptionModule() = default;
StatusOr<std::string> EncryptRecord(base::StringPiece record) const override;
protected:
~TestEncryptionModule() override = default;
};
// A |TestEncryptionModule| that always fails on |EncryptRecord| calls.
class AlwaysFailsEncryptionModule final : public TestEncryptionModule {
public:
AlwaysFailsEncryptionModule() = default;
StatusOr<std::string> EncryptRecord(base::StringPiece record) const override;
protected:
~AlwaysFailsEncryptionModule() override = default;
};
} // namespace test
} // namespace reporting
#endif // CHROME_BROWSER_POLICY_MESSAGING_LAYER_ENCRYPTION_TEST_ENCRYPTION_MODULE_H_
...@@ -5,17 +5,22 @@ ...@@ -5,17 +5,22 @@
#include "chrome/browser/policy/messaging_layer/public/report_queue.h" #include "chrome/browser/policy/messaging_layer/public/report_queue.h"
#include <memory> #include <memory>
#include <string>
#include <utility>
#include "base/json/json_writer.h" #include "base/json/json_writer.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
#include "base/task/task_traits.h" #include "base/task/task_traits.h"
#include "base/task/thread_pool.h" #include "base/task/thread_pool.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/policy/messaging_layer/encryption/encryption_module.h"
#include "chrome/browser/policy/messaging_layer/proto/record.pb.h" #include "chrome/browser/policy/messaging_layer/proto/record.pb.h"
#include "chrome/browser/policy/messaging_layer/public/report_queue_configuration.h" #include "chrome/browser/policy/messaging_layer/public/report_queue_configuration.h"
#include "chrome/browser/policy/messaging_layer/storage/storage_module.h"
#include "chrome/browser/policy/messaging_layer/util/status.h" #include "chrome/browser/policy/messaging_layer/util/status.h"
#include "chrome/browser/policy/messaging_layer/util/status_macros.h" #include "chrome/browser/policy/messaging_layer/util/status_macros.h"
#include "chrome/browser/policy/messaging_layer/util/statusor.h" #include "chrome/browser/policy/messaging_layer/util/statusor.h"
...@@ -25,7 +30,6 @@ ...@@ -25,7 +30,6 @@
namespace reporting { namespace reporting {
using base::MakeRefCounted;
using reporting_messaging_layer::EncryptedRecord; using reporting_messaging_layer::EncryptedRecord;
using reporting_messaging_layer::Record; using reporting_messaging_layer::Record;
using reporting_messaging_layer::WrappedRecord; using reporting_messaging_layer::WrappedRecord;
......
...@@ -6,14 +6,18 @@ ...@@ -6,14 +6,18 @@
#define CHROME_BROWSER_POLICY_MESSAGING_LAYER_PUBLIC_REPORT_QUEUE_H_ #define CHROME_BROWSER_POLICY_MESSAGING_LAYER_PUBLIC_REPORT_QUEUE_H_
#include <memory> #include <memory>
#include <string>
#include <utility>
#include "base/memory/ref_counted.h" #include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/sequence_checker.h" #include "base/sequence_checker.h"
#include "base/sequenced_task_runner.h" #include "base/sequenced_task_runner.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/policy/messaging_layer/encryption/encryption_module.h"
#include "chrome/browser/policy/messaging_layer/proto/record.pb.h" #include "chrome/browser/policy/messaging_layer/proto/record.pb.h"
#include "chrome/browser/policy/messaging_layer/public/report_queue_configuration.h" #include "chrome/browser/policy/messaging_layer/public/report_queue_configuration.h"
#include "chrome/browser/policy/messaging_layer/storage/storage_module.h"
#include "chrome/browser/policy/messaging_layer/util/status.h" #include "chrome/browser/policy/messaging_layer/util/status.h"
#include "chrome/browser/policy/messaging_layer/util/statusor.h" #include "chrome/browser/policy/messaging_layer/util/statusor.h"
#include "components/policy/proto/record_constants.pb.h" #include "components/policy/proto/record_constants.pb.h"
...@@ -21,46 +25,6 @@ ...@@ -21,46 +25,6 @@
namespace reporting { namespace reporting {
// TODO(b/153659559) Temporary StorageModule until the real one is ready.
class StorageModule : public base::RefCounted<StorageModule> {
public:
StorageModule() = default;
StorageModule(const StorageModule& other) = delete;
StorageModule& operator=(const StorageModule& other) = delete;
// AddRecord will add |record| to the |StorageModule| according to the
// provided |priority|. On completion, |callback| will be called.
virtual void AddRecord(reporting_messaging_layer::EncryptedRecord record,
reporting_messaging_layer::Priority priority,
base::OnceCallback<void(Status)> callback) = 0;
protected:
virtual ~StorageModule() = default;
private:
friend base::RefCounted<StorageModule>;
};
// TODO(b/153659559) Temporary EncryptionModule until the real one is ready.
class EncryptionModule : public base::RefCounted<EncryptionModule> {
public:
EncryptionModule() = default;
EncryptionModule(const EncryptionModule& other) = delete;
EncryptionModule& operator=(const EncryptionModule& other) = delete;
// EncryptRecord will attempt to encrypt the provided |record|. On success the
// return value will contain the encrypted string.
virtual StatusOr<std::string> EncryptRecord(base::StringPiece record) = 0;
protected:
virtual ~EncryptionModule() = default;
private:
friend base::RefCounted<EncryptionModule>;
};
// A |ReportQueue| is configured with a |ReportQueueConfiguration|. A // A |ReportQueue| is configured with a |ReportQueueConfiguration|. A
// |ReportQueue| allows a user to |Enqueue| a message for delivery to a handler // |ReportQueue| allows a user to |Enqueue| a message for delivery to a handler
// specified by the |Destination| held by the provided // specified by the |Destination| held by the provided
......
...@@ -6,14 +6,19 @@ ...@@ -6,14 +6,19 @@
#include <stdio.h> #include <stdio.h>
#include <utility>
#include "base/json/json_reader.h" #include "base/json/json_reader.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_refptr.h" #include "base/memory/scoped_refptr.h"
#include "base/optional.h" #include "base/optional.h"
#include "base/synchronization/waitable_event.h" #include "base/synchronization/waitable_event.h"
#include "base/test/task_environment.h" #include "base/test/task_environment.h"
#include "base/values.h" #include "base/values.h"
#include "chrome/browser/policy/messaging_layer/encryption/encryption_module.h"
#include "chrome/browser/policy/messaging_layer/proto/test.pb.h" #include "chrome/browser/policy/messaging_layer/proto/test.pb.h"
#include "chrome/browser/policy/messaging_layer/public/report_queue_configuration.h" #include "chrome/browser/policy/messaging_layer/public/report_queue_configuration.h"
#include "chrome/browser/policy/messaging_layer/storage/storage_module.h"
#include "chrome/browser/policy/messaging_layer/util/status.h" #include "chrome/browser/policy/messaging_layer/util/status.h"
#include "chrome/browser/policy/messaging_layer/util/status_macros.h" #include "chrome/browser/policy/messaging_layer/util/status_macros.h"
#include "chrome/browser/policy/messaging_layer/util/statusor.h" #include "chrome/browser/policy/messaging_layer/util/statusor.h"
...@@ -63,7 +68,7 @@ class TestEncryptionModule : public EncryptionModule { ...@@ -63,7 +68,7 @@ class TestEncryptionModule : public EncryptionModule {
public: public:
TestEncryptionModule() = default; TestEncryptionModule() = default;
StatusOr<std::string> EncryptRecord(base::StringPiece record) override { StatusOr<std::string> EncryptRecord(base::StringPiece record) const override {
return std::string(record); return std::string(record);
} }
...@@ -251,7 +256,7 @@ class AlwaysFailsEncryptionModule final : public TestEncryptionModule { ...@@ -251,7 +256,7 @@ class AlwaysFailsEncryptionModule final : public TestEncryptionModule {
public: public:
AlwaysFailsEncryptionModule() = default; AlwaysFailsEncryptionModule() = default;
StatusOr<std::string> EncryptRecord(base::StringPiece record) override { StatusOr<std::string> EncryptRecord(base::StringPiece record) const override {
return Status(error::UNKNOWN, "Failing for Tests"); return Status(error::UNKNOWN, "Failing for Tests");
} }
......
// 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 <utility>
#include "base/callback.h"
#include "chrome/browser/policy/messaging_layer/proto/record.pb.h"
#include "chrome/browser/policy/messaging_layer/storage/storage_module.h"
#include "chrome/browser/policy/messaging_layer/util/status.h"
#include "components/policy/proto/record_constants.pb.h"
namespace reporting {
void StorageModule::AddRecord(reporting_messaging_layer::EncryptedRecord record,
reporting_messaging_layer::Priority priority,
base::OnceCallback<void(Status)> callback) {
std::move(callback).Run(
Status(error::UNIMPLEMENTED, "AddRecord isn't implemented"));
}
} // namespace reporting
// 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 CHROME_BROWSER_POLICY_MESSAGING_LAYER_STORAGE_STORAGE_MODULE_H_
#define CHROME_BROWSER_POLICY_MESSAGING_LAYER_STORAGE_STORAGE_MODULE_H_
#include <utility>
#include "base/callback.h"
#include "base/memory/ref_counted.h"
#include "chrome/browser/policy/messaging_layer/proto/record.pb.h"
#include "chrome/browser/policy/messaging_layer/util/status.h"
#include "components/policy/proto/record_constants.pb.h"
namespace reporting {
// TODO(b/153659559) Temporary StorageModule until the real one is ready.
class StorageModule : public base::RefCounted<StorageModule> {
public:
StorageModule() = default;
StorageModule(const StorageModule& other) = delete;
StorageModule& operator=(const StorageModule& other) = delete;
// AddRecord will add |record| to the |StorageModule| according to the
// provided |priority|. On completion, |callback| will be called.
virtual void AddRecord(reporting_messaging_layer::EncryptedRecord record,
reporting_messaging_layer::Priority priority,
base::OnceCallback<void(Status)> callback);
protected:
virtual ~StorageModule() = default;
private:
friend base::RefCounted<StorageModule>;
};
} // namespace reporting
#endif // CHROME_BROWSER_POLICY_MESSAGING_LAYER_STORAGE_STORAGE_MODULE_H_
// 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 "chrome/browser/policy/messaging_layer/storage/test_storage_module.h"
#include <utility>
#include "base/callback.h"
#include "chrome/browser/policy/messaging_layer/proto/record.pb.h"
#include "chrome/browser/policy/messaging_layer/public/report_queue.h"
#include "components/policy/proto/record_constants.pb.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace reporting {
namespace test {
using reporting_messaging_layer::EncryptedRecord;
using reporting_messaging_layer::Priority;
void TestStorageModule::AddRecord(EncryptedRecord record,
Priority priority,
base::OnceCallback<void(Status)> callback) {
ASSERT_TRUE(
wrapped_record_.ParseFromString(record.encrypted_wrapped_record()));
priority_ = priority;
std::move(callback).Run(Status::StatusOK());
}
void AlwaysFailsStorageModule::AddRecord(
EncryptedRecord record,
Priority priority,
base::OnceCallback<void(Status)> callback) {
std::move(callback).Run(Status(error::UNKNOWN, "Failing for Tests"));
}
} // namespace test
} // namespace reporting
// 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 CHROME_BROWSER_POLICY_MESSAGING_LAYER_STORAGE_TEST_STORAGE_MODULE_H_
#define CHROME_BROWSER_POLICY_MESSAGING_LAYER_STORAGE_TEST_STORAGE_MODULE_H_
#include <utility>
#include "base/callback.h"
#include "chrome/browser/policy/messaging_layer/proto/record.pb.h"
#include "chrome/browser/policy/messaging_layer/public/report_queue.h"
#include "components/policy/proto/record_constants.pb.h"
namespace reporting {
namespace test {
// A |StorageModule| that stores the wrapped record and priority and calls the
// callback with an OK status.
class TestStorageModule : public StorageModule {
public:
TestStorageModule() = default;
void AddRecord(reporting_messaging_layer::EncryptedRecord record,
reporting_messaging_layer::Priority priority,
base::OnceCallback<void(Status)> callback) override;
reporting_messaging_layer::WrappedRecord wrapped_record() {
return wrapped_record_;
}
reporting_messaging_layer::Priority priority() { return priority_; }
protected:
~TestStorageModule() override = default;
private:
reporting_messaging_layer::WrappedRecord wrapped_record_;
reporting_messaging_layer::Priority priority_;
};
// A |TestStorageModule| that always fails on |AddRecord| calls.
class AlwaysFailsStorageModule final : public TestStorageModule {
public:
AlwaysFailsStorageModule() = default;
void AddRecord(reporting_messaging_layer::EncryptedRecord record,
reporting_messaging_layer::Priority priority,
base::OnceCallback<void(Status)> callback) override;
protected:
~AlwaysFailsStorageModule() override = default;
};
} // namespace test
} // namespace reporting
#endif // CHROME_BROWSER_POLICY_MESSAGING_LAYER_STORAGE_TEST_STORAGE_MODULE_H_
...@@ -3305,8 +3305,12 @@ test("unit_tests") { ...@@ -3305,8 +3305,12 @@ test("unit_tests") {
"../browser/policy/file_selection_dialogs_policy_handler_unittest.cc", "../browser/policy/file_selection_dialogs_policy_handler_unittest.cc",
"../browser/policy/homepage_location_policy_handler_unittest.cc", "../browser/policy/homepage_location_policy_handler_unittest.cc",
"../browser/policy/javascript_policy_handler_unittest.cc", "../browser/policy/javascript_policy_handler_unittest.cc",
"../browser/policy/messaging_layer/encryption/test_encryption_module.cc",
"../browser/policy/messaging_layer/encryption/test_encryption_module.h",
"../browser/policy/messaging_layer/public/report_queue_configuration_unittest.cc", "../browser/policy/messaging_layer/public/report_queue_configuration_unittest.cc",
"../browser/policy/messaging_layer/public/report_queue_unittest.cc", "../browser/policy/messaging_layer/public/report_queue_unittest.cc",
"../browser/policy/messaging_layer/storage/test_storage_module.cc",
"../browser/policy/messaging_layer/storage/test_storage_module.h",
"../browser/policy/messaging_layer/util/status_macros_unittest.cc", "../browser/policy/messaging_layer/util/status_macros_unittest.cc",
"../browser/policy/messaging_layer/util/status_unittest.cc", "../browser/policy/messaging_layer/util/status_unittest.cc",
"../browser/policy/messaging_layer/util/statusor_unittest.cc", "../browser/policy/messaging_layer/util/statusor_unittest.cc",
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment