Commit 1dc5b8fe authored by Jimmy Gong's avatar Jimmy Gong Committed by Commit Bot

Add TickClock to SmbService

- Adds TickClock as a member object of SmbService.
- TickClock will be used for its time stamping functionality to
  time-throttle the calls to host discovery from UpdateSharePath.

Bug: 922273
Test: compiles
Change-Id: I6c9de6cda079f94234a9acae28df8da44505507d
Reviewed-on: https://chromium-review.googlesource.com/c/1444597
Commit-Queue: jimmy gong <jimmyxgong@chromium.org>
Auto-Submit: jimmy gong <jimmyxgong@chromium.org>
Reviewed-by: default avatarZentaro Kavanagh <zentaro@chromium.org>
Cr-Commit-Position: refs/heads/master@{#630524}
parent d1f3480f
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "base/files/file_path.h" #include "base/files/file_path.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/task/post_task.h" #include "base/task/post_task.h"
#include "base/time/default_tick_clock.h"
#include "chrome/browser/chromeos/file_system_provider/mount_path_util.h" #include "chrome/browser/chromeos/file_system_provider/mount_path_util.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h" #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h" #include "chrome/browser/chromeos/profiles/profile_helper.h"
...@@ -108,8 +109,11 @@ std::unique_ptr<TempFileManager> CreateTempFileManager() { ...@@ -108,8 +109,11 @@ std::unique_ptr<TempFileManager> CreateTempFileManager() {
bool SmbService::service_should_run_ = false; bool SmbService::service_should_run_ = false;
SmbService::SmbService(Profile* profile) SmbService::SmbService(Profile* profile,
: provider_id_(ProviderId::CreateFromNativeId("smb")), profile_(profile) { std::unique_ptr<base::TickClock> tick_clock)
: provider_id_(ProviderId::CreateFromNativeId("smb")),
profile_(profile),
tick_clock_(std::move(tick_clock)) {
service_should_run_ = IsEnabledByFlag() && IsAllowedByPolicy(); service_should_run_ = IsEnabledByFlag() && IsAllowedByPolicy();
if (service_should_run_) { if (service_should_run_) {
StartSetup(); StartSetup();
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "base/files/file.h" #include "base/files/file.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/time/time.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h" #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
#include "chrome/browser/chromeos/file_system_provider/provider_interface.h" #include "chrome/browser/chromeos/file_system_provider/provider_interface.h"
#include "chrome/browser/chromeos/file_system_provider/service.h" #include "chrome/browser/chromeos/file_system_provider/service.h"
...@@ -51,7 +52,7 @@ class SmbService : public KeyedService, ...@@ -51,7 +52,7 @@ class SmbService : public KeyedService,
using StartReadDirIfSuccessfulCallback = using StartReadDirIfSuccessfulCallback =
base::OnceCallback<void(bool should_retry_start_read_dir)>; base::OnceCallback<void(bool should_retry_start_read_dir)>;
explicit SmbService(Profile* profile); SmbService(Profile* profile, std::unique_ptr<base::TickClock> tick_clock);
~SmbService() override; ~SmbService() override;
// Gets the singleton instance for the |context|. // Gets the singleton instance for the |context|.
...@@ -239,6 +240,7 @@ class SmbService : public KeyedService, ...@@ -239,6 +240,7 @@ class SmbService : public KeyedService,
static bool service_should_run_; static bool service_should_run_;
const ProviderId provider_id_; const ProviderId provider_id_;
Profile* profile_; Profile* profile_;
std::unique_ptr<base::TickClock> tick_clock_;
std::unique_ptr<TempFileManager> temp_file_manager_; std::unique_ptr<TempFileManager> temp_file_manager_;
std::unique_ptr<SmbShareFinder> share_finder_; std::unique_ptr<SmbShareFinder> share_finder_;
// |mount_id| -> |reply|. Stored callbacks to run after updating credential. // |mount_id| -> |reply|. Stored callbacks to run after updating credential.
......
...@@ -4,6 +4,9 @@ ...@@ -4,6 +4,9 @@
#include "chrome/browser/chromeos/smb_client/smb_service_factory.h" #include "chrome/browser/chromeos/smb_client/smb_service_factory.h"
#include <memory>
#include "base/time/default_tick_clock.h"
#include "chrome/browser/chromeos/authpolicy/auth_policy_credentials_manager.h" #include "chrome/browser/chromeos/authpolicy/auth_policy_credentials_manager.h"
#include "chrome/browser/chromeos/file_system_provider/service_factory.h" #include "chrome/browser/chromeos/file_system_provider/service_factory.h"
#include "chrome/browser/chromeos/smb_client/smb_service.h" #include "chrome/browser/chromeos/smb_client/smb_service.h"
...@@ -43,7 +46,8 @@ bool SmbServiceFactory::ServiceIsCreatedWithBrowserContext() const { ...@@ -43,7 +46,8 @@ bool SmbServiceFactory::ServiceIsCreatedWithBrowserContext() const {
KeyedService* SmbServiceFactory::BuildServiceInstanceFor( KeyedService* SmbServiceFactory::BuildServiceInstanceFor(
content::BrowserContext* profile) const { content::BrowserContext* profile) const {
return new SmbService(Profile::FromBrowserContext(profile)); return new SmbService(Profile::FromBrowserContext(profile),
std::make_unique<base::DefaultTickClock>());
} }
content::BrowserContext* SmbServiceFactory::GetBrowserContextToUse( content::BrowserContext* SmbServiceFactory::GetBrowserContextToUse(
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include <memory> #include <memory>
#include <utility> #include <utility>
#include "base/test/simple_test_tick_clock.h"
#include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system.h" #include "chrome/browser/chromeos/file_system_provider/fake_provided_file_system.h"
#include "chrome/browser/chromeos/file_system_provider/fake_registry.h" #include "chrome/browser/chromeos/file_system_provider/fake_registry.h"
#include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h" #include "chrome/browser/chromeos/file_system_provider/provided_file_system_info.h"
...@@ -52,7 +53,8 @@ class SmbServiceTest : public testing::Test { ...@@ -52,7 +53,8 @@ class SmbServiceTest : public testing::Test {
std::make_unique<file_system_provider::FakeRegistry>()); std::make_unique<file_system_provider::FakeRegistry>());
// Create smb service. // Create smb service.
smb_service_ = std::make_unique<SmbService>(profile_); smb_service_ = std::make_unique<SmbService>(
profile_, std::make_unique<base::SimpleTestTickClock>());
} }
~SmbServiceTest() override {} ~SmbServiceTest() override {}
......
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