blob: c29d4aef10784154c53e3e4e449d7a328b6d61a1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
// Copyright (c) 2012 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/media_galleries/scoped_mtp_device_map_entry.h"
#include "base/bind.h"
#include "chrome/browser/media_galleries/fileapi/media_file_system_backend.h"
#include "chrome/browser/media_galleries/fileapi/mtp_device_map_service.h"
#include "chrome/browser/media_galleries/mtp_device_delegate_impl.h"
#include "content/public/browser/browser_thread.h"
namespace chrome {
namespace {
void OnDeviceAsyncDelegateDestroyed(
const base::FilePath::StringType& device_location) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
MTPDeviceMapService::GetInstance()->RemoveAsyncDelegate(
device_location);
}
void RemoveDeviceDelegate(const base::FilePath::StringType& device_location) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::UI));
content::BrowserThread::PostTask(
content::BrowserThread::IO,
FROM_HERE,
base::Bind(&OnDeviceAsyncDelegateDestroyed, device_location));
}
} // namespace
ScopedMTPDeviceMapEntry::ScopedMTPDeviceMapEntry(
const base::FilePath::StringType& device_location,
const base::Closure& on_destruction_callback)
: device_location_(device_location),
on_destruction_callback_(on_destruction_callback) {
}
void ScopedMTPDeviceMapEntry::Init() {
CreateMTPDeviceAsyncDelegateCallback callback =
base::Bind(&ScopedMTPDeviceMapEntry::OnMTPDeviceAsyncDelegateCreated,
this);
content::BrowserThread::PostTask(
content::BrowserThread::IO,
FROM_HERE,
base::Bind(&CreateMTPDeviceAsyncDelegate,
device_location_,
callback));
}
ScopedMTPDeviceMapEntry::~ScopedMTPDeviceMapEntry() {
RemoveDeviceDelegate(device_location_);
on_destruction_callback_.Run();
}
void ScopedMTPDeviceMapEntry::OnMTPDeviceAsyncDelegateCreated(
MTPDeviceAsyncDelegate* delegate) {
DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
MTPDeviceMapService::GetInstance()->AddAsyncDelegate(
device_location_, delegate);
}
} // namespace chrome
|