Commit 0988704a authored by Evan Stade's avatar Evan Stade Committed by Commit Bot

Remove NOTIFICATION_PROFILE_DESTROYED from sync_file_system_backend.cc

Bug: 268984
Change-Id: Ied766d3006009fbd5534eca799bf095bf48dbc28
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1876083
Commit-Queue: Evan Stade <estade@chromium.org>
Reviewed-by: default avatarHiroki Nakagawa <nhiroki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#709976}
parent 06f433ae
......@@ -10,7 +10,9 @@
#include "base/bind.h"
#include "base/logging.h"
#include "base/task/post_task.h"
#include "chrome/browser/chrome_notification_types.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/sync_file_system/local/local_file_change_tracker.h"
#include "chrome/browser/sync_file_system/local/local_file_sync_context.h"
#include "chrome/browser/sync_file_system/local/syncable_file_system_operation.h"
......@@ -19,7 +21,6 @@
#include "chrome/browser/sync_file_system/syncable_file_system_util.h"
#include "content/public/browser/browser_task_traits.h"
#include "content/public/browser/browser_thread.h"
#include "content/public/browser/notification_service.h"
#include "storage/browser/file_system/file_stream_reader.h"
#include "storage/browser/file_system/file_stream_writer.h"
#include "storage/browser/file_system/file_system_context.h"
......@@ -41,37 +42,9 @@ bool CalledOnUIThread() {
} // namespace
SyncFileSystemBackend::ProfileHolder::ProfileHolder(Profile* profile)
: profile_(profile) {
DCHECK(CalledOnUIThread());
registrar_.Add(this,
chrome::NOTIFICATION_PROFILE_DESTROYED,
content::Source<Profile>(profile_));
}
void SyncFileSystemBackend::ProfileHolder::Observe(
int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
DCHECK(CalledOnUIThread());
DCHECK_EQ(chrome::NOTIFICATION_PROFILE_DESTROYED, type);
DCHECK_EQ(profile_, content::Source<Profile>(source).ptr());
profile_ = nullptr;
registrar_.RemoveAll();
}
Profile* SyncFileSystemBackend::ProfileHolder::GetProfile() {
DCHECK(CalledOnUIThread());
return profile_;
}
SyncFileSystemBackend::SyncFileSystemBackend(Profile* profile)
: context_(nullptr),
skip_initialize_syncfs_service_for_testing_(false) {
: profile_(profile) {
DCHECK(CalledOnUIThread());
if (profile)
profile_holder_.reset(new ProfileHolder(profile));
// Register the service name here to enable to crack an URL on SyncFileSystem
// even if SyncFileSystemService has not started yet.
RegisterSyncableFileSystem();
......@@ -82,11 +55,6 @@ SyncFileSystemBackend::~SyncFileSystemBackend() {
GetDelegate()->file_task_runner()->DeleteSoon(
FROM_HERE, change_tracker_.release());
}
if (profile_holder_ && !CalledOnUIThread()) {
BrowserThread::DeleteSoon(
BrowserThread::UI, FROM_HERE, profile_holder_.release());
}
}
// static
......@@ -277,14 +245,14 @@ void SyncFileSystemBackend::InitializeSyncFileSystemService(
return;
}
if (!profile_holder_->GetProfile()) {
if (!g_browser_process->profile_manager()->IsValidProfile(profile_)) {
// Profile was destroyed.
callback.Run(SYNC_FILE_ERROR_FAILED);
return;
}
SyncFileSystemService* service = SyncFileSystemServiceFactory::GetForProfile(
profile_holder_->GetProfile());
SyncFileSystemService* service =
SyncFileSystemServiceFactory::GetForProfile(profile_);
DCHECK(service);
service->InitializeForApp(context_, origin_url, callback);
}
......
......@@ -10,16 +10,15 @@
#include <memory>
#include "base/macros.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/sync_file_system/sync_callbacks.h"
#include "chrome/browser/sync_file_system/sync_status_code.h"
#include "content/public/browser/notification_observer.h"
#include "content/public/browser/notification_registrar.h"
#include "storage/browser/file_system/file_system_backend.h"
#include "storage/browser/file_system/file_system_quota_util.h"
#include "storage/browser/file_system/sandbox_file_system_backend_delegate.h"
#include "storage/browser/file_system/task_runner_bound_observer_list.h"
class Profile;
namespace sync_file_system {
class LocalFileChangeTracker;
......@@ -81,34 +80,19 @@ class SyncFileSystemBackend : public storage::FileSystemBackend {
void set_sync_context(LocalFileSyncContext* sync_context);
private:
class ProfileHolder : public content::NotificationObserver {
public:
explicit ProfileHolder(Profile* profile);
// NotificationObserver override.
void Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) override;
Profile* GetProfile();
private:
content::NotificationRegistrar registrar_;
Profile* profile_;
};
// Not owned.
storage::FileSystemContext* context_;
storage::FileSystemContext* context_ = nullptr;
std::unique_ptr<LocalFileChangeTracker> change_tracker_;
scoped_refptr<LocalFileSyncContext> sync_context_;
// Should be accessed on the UI thread.
std::unique_ptr<ProfileHolder> profile_holder_;
// |profile_| will initially be valid but may be destroyed before |this|, so
// it should be checked before being accessed.
Profile* profile_;
// A flag to skip the initialization sequence of SyncFileSystemService for
// testing.
bool skip_initialize_syncfs_service_for_testing_;
bool skip_initialize_syncfs_service_for_testing_ = false;
storage::SandboxFileSystemBackendDelegate* GetDelegate() const;
......
......@@ -21,7 +21,6 @@ class SyncFileSystemService;
class SyncFileSystemServiceFactory : public BrowserContextKeyedServiceFactory {
public:
static SyncFileSystemService* GetForProfile(Profile* profile);
static SyncFileSystemService* FindForProfile(Profile* profile);
static SyncFileSystemServiceFactory* GetInstance();
// This overrides the local/remote service for testing.
......
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