0
Commit Graph

59 Commits

Author SHA1 Message Date
Arthur Sonzogni
c686e8f4fd Rename {absl => std}::optional in //content/
Automated patch, intended to be effectively a no-op.

Context:
https://groups.google.com/a/chromium.org/g/cxx/c/nBD_1LaanTc/m/ghh-ZZhWAwAJ?utm_medium=email&utm_source=footer

As of https://crrev.com/1204351, absl::optional is now a type alias for
std::optional. We should migrate toward it.

Script:
```
function replace {
  echo "Replacing $1 by $2"
  git grep -l "$1" \
    | cut -f1 -d: \
    | grep \
      -e "^content" \
    | sort \
    | uniq \
    | grep \
      -e "\.h" \
      -e "\.cc" \
      -e "\.mm" \
      -e "\.py" \
    | xargs sed -i "s/$1/$2/g"
}
replace "absl::make_optional" "std::make_optional"
replace "absl::optional" "std::optional"
replace "absl::nullopt" "std::nullopt"
replace "absl::in_place" "std::in_place"
replace "absl::in_place_t" "std::in_place_t"
replace "\"third_party\/abseil-cpp\/absl\/types\/optional.h\"" "<optional>"
git cl format
```

# Skipping unrelated "check_network_annotation" errors.
NOTRY=True

Bug: chromium:1500249
Change-Id: Icfd31a71d8faf63a2e8d5401127e7ee74cc1c413
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5185537
Auto-Submit: Arthur Sonzogni <arthursonzogni@chromium.org>
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Owners-Override: Avi Drissman <avi@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: danakj <danakj@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1245739}
2024-01-11 08:36:37 +00:00
Avi Drissman
4e1b7bc33d Update copyright headers in content/
The methodology used to generate this CL is documented in
https://crbug.com/1098010#c34.

No-Try: true
No-Presubmit: true
Bug: 1098010
Change-Id: I8c0f009d16350271f07d8e5e561085822cc9dd27
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3895935
Owners-Override: Avi Drissman <avi@chromium.org>
Reviewed-by: Mark Mentovai <mark@chromium.org>
Commit-Queue: Mark Mentovai <mark@chromium.org>
Auto-Submit: Avi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1047456}
2022-09-15 14:03:50 +00:00
Xiaohan Wang
1ecfd006fd content: Use BUILDFLAG for OS checking
Use BUILDFLAG(IS_XXX) instead of defined(OS_XXX).

Generated by `os_buildflag_migration.py` (https://crrev.com/c/3311983).

R=thakis@chromium.org

Bug: 1234043
Test: No functionality change
Change-Id: Ia0eae6f9396065e190929d42600012c9324c07e9
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3399774
Commit-Queue: Xiaohan Wang <xhwang@chromium.org>
Owners-Override: Xiaohan Wang <xhwang@chromium.org>
Auto-Submit: Xiaohan Wang <xhwang@chromium.org>
Reviewed-by: Nico Weber <thakis@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Owners-Override: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#961157}
2022-01-19 22:33:10 +00:00
Patrick Monette
643cdf6190 Replace base/task/ temporary forward headers with their final locations
Note to QA: This merely changes includes and should not be blamed
for files it touched.

Bug: 1255932
Change-Id: I1ce4e31efd5792ebf2080812e665cae838a54972
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3226943
Reviewed-by: Gabriel Charette <gab@chromium.org>
Owners-Override: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/main@{#932153}
2021-10-15 19:13:42 +00:00
Patrick Monette
3d7d70920a Replace task-related headers to their equivalent in base/task/
This CL was generated by using tools/git/move_source_file.py to change
the includes for those files:
base/bind_post_task.h
base/deferred_sequenced_task_runner.h
base/post_task_and_reply_with_result_internal.h
base/sequenced_task_runner.h
base/sequenced_task_runner_helpers.h
base/single_thread_task_runner.h
base/task_runner.h
base/task_runner_util.h
base/updateable_sequenced_task_runner.h

Then formatted using "git cl format". DEPS files were fixed with a
simple search and replace script.

Bug: 1255932
Change-Id: I0d9b5ddd9260fde5e4581e6c6e0080bdb0ed2c44
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3209175
Reviewed-by: Gabriel Charette <gab@chromium.org>
Owners-Override: Gabriel Charette <gab@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/main@{#929867}
2021-10-08 20:27:23 +00:00
Anton Bikineev
f62d1bf48e content: Replace base::Optional and friends with absl counterparts
This replaces:
- base::Optional -> absl::optional
- include "base/optional.h"
  ->
  include "third_party/abseil-cpp/absl/types/optional.h"
- base::nullopt -> absl::nullopt
- base::make_optional -> absl::make_optional

Bug: 1202909
Change-Id: Ie9f37bcbf6115632a19f4d063387d07b3723926f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2897246
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Peter Kasting <pkasting@chromium.org>
Owners-Override: Peter Kasting <pkasting@chromium.org>
Cr-Commit-Position: refs/heads/master@{#883270}
2021-05-15 17:56:07 +00:00
John Abd-El-Malek
f3243dc72e Rename BrowserProcessSubThread to BrowserProcessIOThread to make it clear what it's used for now.
We don't create it in production anymore for UI thread. This wasn't obvious, e.g. see the fix in https://crrev.com/c/2877684.

Bug: 904556
Change-Id: I4e6eaeeafd6144c30c4822a11806dfa24e4363e4
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2878894
Commit-Queue: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#880433}
2021-05-07 16:20:01 +00:00
Gabriel Charette
e7cdc5cd07 [BrowserThread] Migration callers without full content:: namespace
Note to QA: This CL is purely mechanical and shouldn't be blamed
for future regressions on touched files.

This is a follow-up to https://chromium-review.googlesource.com/c/chromium/src/+/2211138
which already removed all usage using content::BrowserThread.

Hence this script now matches unqualified BrowserThread:: without
risking having "content::" be selected as "traits_before" by the regex
(ran on same revision as step ).

content:: is now always added if outside namespace content {}
(deleting unused using content::BrowserThread; decls)

Script @ https://crbug.com/1026641#c92

(will TBR fdoray@ post-review for mechanical change)
TBR=fdoray@hchromium.org

AX-Relnotes: n/a.
Bug: 1026641
Change-Id: I51ae2f83eb17d19b54563fd9b4fc040d2aa0c948
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2212469
Commit-Queue: Gabriel Charette <gab@chromium.org>
Reviewed-by: François Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#772458}
2020-05-27 23:35:05 +00:00
Gabriel Charette
798fde7bc9 [Browser/WebTaskEnvironment] Mass-migrate away from Test(Browser|Web)ThreadBundle
This is
 1) s/TestBrowserThreadBundle/BrowserTaskEnvironment/ on src/
 2) s/([^/])\b\w*thread_bundle(_)?/\1task_environment\2/ on files modified in (1)
 3) git cl format
 4) Manually fix up remainder "ThreadBundle" and "thread_bundle" found via
    string search on the whole of src/.

For ease of review:
 * Step  is the diff between patch sets 1..2
 * Step  is the diff between patch sets 2..3

TBR=dcheng@chromium.org
(for post-review owners bypass per mechanical change)

Bug: 992483
Change-Id: I4945141f6d78bdc6c98444198e5012ddc8e5bff0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1758440
Reviewed-by: Gabriel Charette <gab@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Auto-Submit: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#688755}
2019-08-20 22:24:04 +00:00
Sami Kyostila
8e4d5a915e content/browser: Always specify thread affinity when posting tasks
*** Note: There is no behavior change from this patch. ***

The PostTask APIs will shortly be changed to require all tasks to explicitly
specify their thread affinity, i.e., whether the task should run on the thread
pool or a specific named thread such as a BrowserThread. This patch updates all
call sites with thread affinity annotation. We also remove the "WithTraits"
suffix to make the call sites more readable.

Before:

    // Thread pool task.
    base::PostTaskWithTraits(FROM_HERE, {...}, ...);

    // UI thread task.
    base::PostTaskWithTraits(FROM_HERE, {BrowserThread::UI, ...}, ...);

After:

    // Thread pool task.
    base::PostTask(FROM_HERE, {base::ThreadPool(), ...}, ...);

    // UI thread task.
    base::PostTask(FROM_HERE, {BrowserThread::UI, ...}, ...);

This patch was semi-automatically prepared with these steps:

    1. Patch in https://chromium-review.googlesource.com/c/chromium/src/+/1635827
       to make thread affinity a build-time requirement.
    2. Run an initial pass with a clang rewriter:
       https://chromium-review.googlesource.com/c/chromium/src/+/1635623
    3. ninja -C out/Debug | grep 'requested here' | cut -d: -f1-3 | sort | \
           uniq > errors.txt
    4. while read line; do
         f=$(echo $line | cut -d: -f 1)
         r=$(echo $line | cut -d: -f 2)
         c=$(echo $line | cut -d: -f 3)
         sed -i "${r}s/./&base::ThreadPool(),/$c" $f
       done < errors.txt
    5. GOTO 3 until build succeeds.
    6. Remove the "WithTraits" suffix from task API call sites:

       $ tools/git/mffr.py -i <(cat <<EOF
       [
         ["PostTaskWithTraits",                            "PostTask"],
         ["PostDelayedTaskWithTraits",                     "PostDelayedTask"],
         ["PostTaskWithTraitsAndReply",                    "PostTaskAndReply"],
         ["CreateTaskRunnerWithTraits",                    "CreateTaskRunner"],
         ["CreateSequencedTaskRunnerWithTraits",           "CreateSequencedTaskRunner"],
         ["CreateUpdateableSequencedTaskRunnerWithTraits", "CreateUpdateableSequencedTaskRunner"],
         ["CreateSingleThreadTaskRunnerWithTraits",        "CreateSingleThreadTaskRunner"],
         ["CreateCOMSTATaskRunnerWithTraits",              "CreateCOMSTATaskRunner"]
       ]
       EOF
       )

This CL was uploaded by git cl split.

R=boliu@chromium.org, tsepez@chromium.org

Bug: 968047
Change-Id: I346372d16a3856186ea74d14e0dd8a12f7cacae5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1729589
Commit-Queue: Sami Kyöstilä <skyostil@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Bo <boliu@chromium.org>
Auto-Submit: Sami Kyöstilä <skyostil@chromium.org>
Cr-Commit-Position: refs/heads/master@{#683554}
2019-08-02 12:45:05 +00:00
Francois Doray
c186829bed Allow usage of FileDescriptorWatcher on the UI thread.
FileDescriptorWatcher::WatchReadable/WatchWritable delegate the
responsibility to watch a file descriptor to another thread. There
is no reason to prevent their usage on the UI thread.

Support for FileDescriptorWatcher::WatchReadable/WatchWritable on the
UI thread is needed to support lock screen notifications on ChromeOS.

Discussion: https://groups.google.com/a/google.com/forum/?utm_medium=email&utm_source=footer#!msg/chrome-scheduler/rFN0rTSmfho/Fe9m0YS5CAAJ
Change-Id: Ib82481a8d7224285055447ce64de738764c1c53f
Reviewed-on: https://chromium-review.googlesource.com/c/1349468
Commit-Queue: François Doray <fdoray@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#614240}
2018-12-06 02:29:43 +00:00
Eric Seckler
4d89f64d9c content: Remove BrowserThread::Post*Task / GetTaskRunnerForThread.
This removes BrowserThread::Post(NonNestable|)(Delayed|)Task and moves
GetTaskRunnerForThread into the impl (it's still used to vend
TaskRunners in BrowserTaskExecutor).

These methods have been replaced by base/post_task.h in conjunction
with content/public/browser/browser_task_traits.h

Bug: 878356
Change-Id: Ia122dc0921769f43da9271ddd6e1ce2f402df779
Reviewed-on: https://chromium-review.googlesource.com/1235728
Commit-Queue: Eric Seckler <eseckler@chromium.org>
Reviewed-by: Dmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#592879}
2018-09-20 18:16:16 +00:00
Alex Clarke
7dc412de2b Introduce content::BrowserTaskExecutor
This class's job is to map base::TaskTraits to actual task queues
for the browser process.  This was split off from
https://chromium-review.googlesource.com/c/chromium/src/+/1214223
and is a pre-requisite for the BrowserUIThreadScheduler.

Design doc: https://docs.google.com/document/d/1z1BDq9vzcEpkhN9LSPF5XMnZ0kLJ8mWWkNAi4OI7cos/edit#

BUG=863341, 872372

Change-Id: Ic80e8f66cf245cca136c29387031d111e57fa713
Reviewed-on: https://chromium-review.googlesource.com/1224115
Commit-Queue: Alex Clarke <alexclarke@chromium.org>
Reviewed-by: Jochen Eisinger <jochen@chromium.org>
Reviewed-by: Eric Seckler <eseckler@chromium.org>
Cr-Commit-Position: refs/heads/master@{#591316}
2018-09-14 10:02:31 +00:00
Eric Seckler
e329cb9df7 content: Add a TaskTraits extension and TaskExecutor for BrowserThreads.
This allows using //base/task/post_task.h for posting tasks to a
BrowserThread by specifying a BrowserThread::ID as a task trait.

Also adds a content::NonNestable task trait to support non-nestable
tasks in base::PostTaskWithTraits.

In the future, we will add further traits to facilitate scheduling
tasks onto different SequenceManager queues on the UI thread, see:
https://docs.google.com/document/d/1z1BDq9vzcEpkhN9LSPF5XMnZ0kLJ8mWWkNAi4OI7cos/edit?usp=sharing

Bug: 867421, 863341, 878356
Change-Id: Id8b7bc2e374917ceb421c7f6139790e6f1457511
Reviewed-on: https://chromium-review.googlesource.com/1181364
Commit-Queue: Eric Seckler <eseckler@chromium.org>
Reviewed-by: Sami Kyöstilä <skyostil@chromium.org>
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: François Doray <fdoray@chromium.org>
Reviewed-by: Alex Clarke <alexclarke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#586728}
2018-08-28 16:09:40 +00:00
Gabriel Charette
9ed29db5e8 Make BrowserThreadImpl lock-less
Sampling profiler highlights high contention on this lock:
crbug.com/821034.

Initializing/tear down was already single-threaded (tear down had to be moved
from BrowserProcessSubThread::Cleanup() to ~BrowserProcessSubThread() to
enforce this with a ThreadChecker however). Add dchecks to confirm/enforce
this and remove the lock which is usuless on data structures that are now (as
of series of changes over the last year) read-only after startup.

Use atomics to protect reads across the RUNNING=>SHUTDOWN boundary.

Bug: 821034
Change-Id: I7800048bff51ad79cb10ee89fd3a0a31534c393e
Reviewed-on: https://chromium-review.googlesource.com/973556
Commit-Queue: Gabriel Charette <gab@chromium.org>
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546212}
2018-03-27 19:48:00 +00:00
Gabriel Charette
8eb4dff991 Reland "Refactor BrowserThreadImpl, BrowserProcessSubThread, and BrowserMainLoop"
This is a reland of d260e9cf66

It was reverted because of crbug.com/824716, these weren't new crashes
but known crashes mislabeled as a fallout of this change.
http://cl/190471699 fixes the crash backend to not rely on
"content::BrowserThreadImpl::IOThreadRun" being in the signature.

Only diff in this CL is to use base::debug::Alias() in methods that we
don't want optimized (i.e. IOThreadRun) out as CHECK_GT was seen as
optimized out in some of the reported crashes (even though the same
pattern as before was used by this CL..?)

Original change's description:
> Refactor BrowserThreadImpl, BrowserProcessSubThread, and BrowserMainLoop
>
> This brings back the invariant that BrowserThread::IO isn't available
> before BrowserMainLoop::CreateThreads(). This was broken to fix issue
> 729596 to bring up the thread earlier for ServiceManager but it is
> important that code that posts to BrowserThread::IO statically have an
> happens-after relationship to BrowserMainLoop::CreateThreads(). Exposing
> it statically earlier put that invariant at risk.
>
> Thankfully fixing issue 815225 resulted in finally reaching the long
> sought goal of only having BrowserThread::UI/IO. Now that the IO thread
> is also kicked off before it's named statically, BrowserThreadImpl no
> longer needs to be a base::Thread, hence this refactoring.
>
> Before this CL:
>  * BrowserThreadImpl was a base::Thread
>    (could be a fake thread if SetMessageLoop was used)
>  * BrowserProcessSubThread was a BrowserThreadImpl
>    (performed a bit more initialization)
>  * BrowserProcessSubThread was only used in production (in
>    BrowserMainLoop)
>  * BrowserThreadImpl was used for fake threads (BrowserMainLoop for
>    BrowserThread::UI) and for testing (TestBrowserThread(Impl)).
>  * BrowserThreadImpl overrode Init/Run/CleanUp() from base::Thread to
>    perform some sanity checks as well as drive IOThread's Delegate (ref.
>    BrowserThread::SetIOThreadDelegate())
>  * BrowserProcessSubThread re-overrode Init/Run/CleanUp() to perform
>    per-thread //content initialization (tests missed out on that per
>    TestBrowserThread bypassing BrowserProcessSubThread by directly
>    subclassing BrowserThreadImpl).
>
> With this CL:
>  * BrowserThreadImpl is merely a scoped object that binds a provided
>    SingleThreadTaskRunner to a BrowserThread::ID.
>  * BrowserProcessSubThread is a base::Thread and performs all of the
>    initialization and cleanup specific to //content (this means it now
>    also manages BrowserThread::SetIOThreadDelegate())
>  * BrowserProcessSubThread can be brought up early before being bound to
>    a BrowserThread::ID (BrowserMainLoop handles that through
>    BrowserProcessSubThread ::RegisterAsBrowserThread())
>
> Unfortunate exceptions required for this CL:
>  * IOThread::Init() (invoked through BrowserThreadDelegate) perfoms
>    blocking operations this was previously performed before installed
>    the ThreadRestrictions on BrowserThread::IO. But now that //content
>    is initialized after bringing up the thread, a
>    base::ScopedAllowBlocking is required in scope of IOThread::Init().
>  * TestBrowserThread previously bypassing BrowserProcessSubThread by
>    directly subclassing BrowserThreadImpl meant it wasn't subject to
>    ThreadRestrictions (unfortunate becomes it denies allowance
>    verification to product code running in unit tests). Adding it back
>    causes DCHECKs, as such
>    BrowserProcessSubThread::AllowBlockingForTesting was added to allow
>    this CL to pass CQ.
>
> Of note:
>  * BrowserProcessSubThread is still written as though it supports many
>    BrowserThread::IDs but in practice it's mostly always
>    BrowserThread::IO (except in ThreadWatcherTest I think). This change
>    was big enough that I didn't bother also breaking that
>    generalization.
>  * BrowserThreadImpl's constructor was made private to ensure only
>    BrowserProcessSubThread and a few select callers get to drive it (to
>    avoid previous missed initialization issues)
>  * Atomics to manage BrowserThread::SetIOThreadDelegate were removed.
>    Restriction was instead added that this only be called before
>    initialization and after shutdown (this was already the case).
>
> Follow-ups to this CL:
>  * //ios duplicates this logic and will need to undergo the same change
>    as a follow-up
>  * Fixing ios will allow removal of base::Thread::SetMessageLoop hack :)
>  * Removing BrowserThreadGlobals::lock_ to address crbug.com/821034 will
>    be much easier
>  * BrowserThread post APIs should DCHECK rather than no-op if using a
>    BrowserThread::ID before it's registered.
>
> Bug: 815225, 821034, 729596
> Change-Id: If1038f23079df72203b1e95c7d26647f8824a726
> Reviewed-on: https://chromium-review.googlesource.com/969104
> Reviewed-by: John Abd-El-Malek <jam@chromium.org>
> Commit-Queue: Gabriel Charette <gab@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#544440}

TBR=jam@chromium.org

Bug: 815225, 821034, 729596, 824716
Change-Id: I9a180975c69a008f8519d1d3d44663aa58a74a92
Reviewed-on: https://chromium-review.googlesource.com/980793
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: Gabriel Charette <gab@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#546104}
2018-03-27 14:22:54 +00:00
Matt Falkenhagen
fa239c8c41 Revert "Refactor BrowserThreadImpl, BrowserProcessSubThread, and BrowserMainLoop"
This reverts commit d260e9cf66.

Reason for revert: In Windows Canary versions since 67.0.3377.0, where this commit landed, IO thread hang reports have spiked dramatically. It is now the  browser crash report on Windows Canary at 33% of reports. I'm speculatively reverting this to see if the crash rate heals.

Original change's description:
> Refactor BrowserThreadImpl, BrowserProcessSubThread, and BrowserMainLoop
>
> This brings back the invariant that BrowserThread::IO isn't available
> before BrowserMainLoop::CreateThreads(). This was broken to fix issue
> 729596 to bring up the thread earlier for ServiceManager but it is
> important that code that posts to BrowserThread::IO statically have an
> happens-after relationship to BrowserMainLoop::CreateThreads(). Exposing
> it statically earlier put that invariant at risk.
>
> Thankfully fixing issue 815225 resulted in finally reaching the long
> sought goal of only having BrowserThread::UI/IO. Now that the IO thread
> is also kicked off before it's named statically, BrowserThreadImpl no
> longer needs to be a base::Thread, hence this refactoring.
>
> Before this CL:
>  * BrowserThreadImpl was a base::Thread
>    (could be a fake thread if SetMessageLoop was used)
>  * BrowserProcessSubThread was a BrowserThreadImpl
>    (performed a bit more initialization)
>  * BrowserProcessSubThread was only used in production (in
>    BrowserMainLoop)
>  * BrowserThreadImpl was used for fake threads (BrowserMainLoop for
>    BrowserThread::UI) and for testing (TestBrowserThread(Impl)).
>  * BrowserThreadImpl overrode Init/Run/CleanUp() from base::Thread to
>    perform some sanity checks as well as drive IOThread's Delegate (ref.
>    BrowserThread::SetIOThreadDelegate())
>  * BrowserProcessSubThread re-overrode Init/Run/CleanUp() to perform
>    per-thread //content initialization (tests missed out on that per
>    TestBrowserThread bypassing BrowserProcessSubThread by directly
>    subclassing BrowserThreadImpl).
>
> With this CL:
>  * BrowserThreadImpl is merely a scoped object that binds a provided
>    SingleThreadTaskRunner to a BrowserThread::ID.
>  * BrowserProcessSubThread is a base::Thread and performs all of the
>    initialization and cleanup specific to //content (this means it now
>    also manages BrowserThread::SetIOThreadDelegate())
>  * BrowserProcessSubThread can be brought up early before being bound to
>    a BrowserThread::ID (BrowserMainLoop handles that through
>    BrowserProcessSubThread ::RegisterAsBrowserThread())
>
> Unfortunate exceptions required for this CL:
>  * IOThread::Init() (invoked through BrowserThreadDelegate) perfoms
>    blocking operations this was previously performed before installed
>    the ThreadRestrictions on BrowserThread::IO. But now that //content
>    is initialized after bringing up the thread, a
>    base::ScopedAllowBlocking is required in scope of IOThread::Init().
>  * TestBrowserThread previously bypassing BrowserProcessSubThread by
>    directly subclassing BrowserThreadImpl meant it wasn't subject to
>    ThreadRestrictions (unfortunate becomes it denies allowance
>    verification to product code running in unit tests). Adding it back
>    causes DCHECKs, as such
>    BrowserProcessSubThread::AllowBlockingForTesting was added to allow
>    this CL to pass CQ.
>
> Of note:
>  * BrowserProcessSubThread is still written as though it supports many
>    BrowserThread::IDs but in practice it's mostly always
>    BrowserThread::IO (except in ThreadWatcherTest I think). This change
>    was big enough that I didn't bother also breaking that
>    generalization.
>  * BrowserThreadImpl's constructor was made private to ensure only
>    BrowserProcessSubThread and a few select callers get to drive it (to
>    avoid previous missed initialization issues)
>  * Atomics to manage BrowserThread::SetIOThreadDelegate were removed.
>    Restriction was instead added that this only be called before
>    initialization and after shutdown (this was already the case).
>
> Follow-ups to this CL:
>  * //ios duplicates this logic and will need to undergo the same change
>    as a follow-up
>  * Fixing ios will allow removal of base::Thread::SetMessageLoop hack :)
>  * Removing BrowserThreadGlobals::lock_ to address crbug.com/821034 will
>    be much easier
>  * BrowserThread post APIs should DCHECK rather than no-op if using a
>    BrowserThread::ID before it's registered.
>
> Bug: 815225, 821034, 729596
> Change-Id: If1038f23079df72203b1e95c7d26647f8824a726
> Reviewed-on: https://chromium-review.googlesource.com/969104
> Reviewed-by: John Abd-El-Malek <jam@chromium.org>
> Commit-Queue: Gabriel Charette <gab@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#544440}

TBR=gab@chromium.org,jam@chromium.org
NOPRESUBMIT=true

# Not skipping CQ checks because original CL landed > 1 day ago.
# falken: Skipping presubmit to use deprecated ThreadResrictions::DisallowWaiting().

Bug: 815225, 821034, 729596
Change-Id: I2be97c5d8183497c005ab397c871f625b034d850
Reviewed-on: https://chromium-review.googlesource.com/979752
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545725}
2018-03-26 04:21:19 +00:00
Gabriel Charette
d260e9cf66 Refactor BrowserThreadImpl, BrowserProcessSubThread, and BrowserMainLoop
This brings back the invariant that BrowserThread::IO isn't available
before BrowserMainLoop::CreateThreads(). This was broken to fix issue
729596 to bring up the thread earlier for ServiceManager but it is
important that code that posts to BrowserThread::IO statically have an
happens-after relationship to BrowserMainLoop::CreateThreads(). Exposing
it statically earlier put that invariant at risk.

Thankfully fixing issue 815225 resulted in finally reaching the long
sought goal of only having BrowserThread::UI/IO. Now that the IO thread
is also kicked off before it's named statically, BrowserThreadImpl no
longer needs to be a base::Thread, hence this refactoring.

Before this CL:
 * BrowserThreadImpl was a base::Thread
   (could be a fake thread if SetMessageLoop was used)
 * BrowserProcessSubThread was a BrowserThreadImpl
   (performed a bit more initialization)
 * BrowserProcessSubThread was only used in production (in
   BrowserMainLoop)
 * BrowserThreadImpl was used for fake threads (BrowserMainLoop for
   BrowserThread::UI) and for testing (TestBrowserThread(Impl)).
 * BrowserThreadImpl overrode Init/Run/CleanUp() from base::Thread to
   perform some sanity checks as well as drive IOThread's Delegate (ref.
   BrowserThread::SetIOThreadDelegate())
 * BrowserProcessSubThread re-overrode Init/Run/CleanUp() to perform
   per-thread //content initialization (tests missed out on that per
   TestBrowserThread bypassing BrowserProcessSubThread by directly
   subclassing BrowserThreadImpl).

With this CL:
 * BrowserThreadImpl is merely a scoped object that binds a provided
   SingleThreadTaskRunner to a BrowserThread::ID.
 * BrowserProcessSubThread is a base::Thread and performs all of the
   initialization and cleanup specific to //content (this means it now
   also manages BrowserThread::SetIOThreadDelegate())
 * BrowserProcessSubThread can be brought up early before being bound to
   a BrowserThread::ID (BrowserMainLoop handles that through
   BrowserProcessSubThread ::RegisterAsBrowserThread())

Unfortunate exceptions required for this CL:
 * IOThread::Init() (invoked through BrowserThreadDelegate) perfoms
   blocking operations this was previously performed before installed
   the ThreadRestrictions on BrowserThread::IO. But now that //content
   is initialized after bringing up the thread, a
   base::ScopedAllowBlocking is required in scope of IOThread::Init().
 * TestBrowserThread previously bypassing BrowserProcessSubThread by
   directly subclassing BrowserThreadImpl meant it wasn't subject to
   ThreadRestrictions (unfortunate becomes it denies allowance
   verification to product code running in unit tests). Adding it back
   causes DCHECKs, as such
   BrowserProcessSubThread::AllowBlockingForTesting was added to allow
   this CL to pass CQ.

Of note:
 * BrowserProcessSubThread is still written as though it supports many
   BrowserThread::IDs but in practice it's mostly always
   BrowserThread::IO (except in ThreadWatcherTest I think). This change
   was big enough that I didn't bother also breaking that
   generalization.
 * BrowserThreadImpl's constructor was made private to ensure only
   BrowserProcessSubThread and a few select callers get to drive it (to
   avoid previous missed initialization issues)
 * Atomics to manage BrowserThread::SetIOThreadDelegate were removed.
   Restriction was instead added that this only be called before
   initialization and after shutdown (this was already the case).

Follow-ups to this CL:
 * //ios duplicates this logic and will need to undergo the same change
   as a follow-up
 * Fixing ios will allow removal of base::Thread::SetMessageLoop hack :)
 * Removing BrowserThreadGlobals::lock_ to address crbug.com/821034 will
   be much easier
 * BrowserThread post APIs should DCHECK rather than no-op if using a
   BrowserThread::ID before it's registered.

Bug: 815225, 821034, 729596
Change-Id: If1038f23079df72203b1e95c7d26647f8824a726
Reviewed-on: https://chromium-review.googlesource.com/969104
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544440}
2018-03-20 18:10:45 +00:00
Gabriel Charette
2e84e1812b More BrowserThread cleanups after removal of PROCESS_LAUNCHER thread.
Follow-up to https://chromium-review.googlesource.com/c/chromium/src/+/941264

Further cleanup of WithBaseSyncPrimitives() is done in
https://chromium-review.googlesource.com/c/chromium/src/+/961455
as that may have side-effects that risk a revert.

Bug: 815225, 689520
Change-Id: I8ba8bb6709b7d8cc88e07e0f915c3c00d0a80cc2
Reviewed-on: https://chromium-review.googlesource.com/961451
Commit-Queue: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: Alexei Svitkine <asvitkine@chromium.org>
Cr-Commit-Position: refs/heads/master@{#543311}
2018-03-15 05:49:40 +00:00
Xi Han
066637cf13 [Servicification] Create BrowserThread::IO earlier.
In this CL, we split the creation of the BrowserThread::IO thread and
initialization of its delegate:

1. The BrowserThread::IO is created in the
   BrowserMainLoop::PostMainMessageLoopStart() after the UI thread
   is created. Adjust the tracing events in the BrowserMainLoop.
2. Simplify the logic in BrowserMainLoop::CreateThreads() since only
   the launcher thread is created there. Initializes the
   delegate of the BrowserThread::IO there.
3. Update the logic in the BrowserThreadImpl when checking whether
   the BrowserThread::IO has initialized.
4. Update BrowserMainLoopTest and BrowserProcessImplTest.

 This is the first step of starting ServiceManager earlier.

Bug: 729596
Change-Id: I7a08fd7c7bf5548f8039c8c38152ecfde3bd20c4
Reviewed-on: https://chromium-review.googlesource.com/905424
Commit-Queue: Xi Han <hanxi@chromium.org>
Reviewed-by: Ken Rockot <rockot@chromium.org>
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: Yaron Friedman <yfriedman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#537318}
2018-02-16 16:41:47 +00:00
Gabriel Charette
9f99a202a7 Finally remove all deprecated BrowserThreads and cleanup remaining dependencies.
This is the final piece in the attempt to reland
https://chromium-review.googlesource.com/c/chromium/src/+/705775

Bug: 804345
Change-Id: I240576ae186886ae9b76c50a7920aed37b3a4ff1

TBR=avi@chromium.org, jam@chromium.org (fwd'ing from https://chromium-review.googlesource.com/c/chromium/src/+/705775)

Change-Id: I240576ae186886ae9b76c50a7920aed37b3a4ff1
Reviewed-on: https://chromium-review.googlesource.com/890263
Commit-Queue: Gabriel Charette <gab@chromium.org>
Reviewed-by: Alexei Svitkine <asvitkine@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Cr-Commit-Position: refs/heads/master@{#533640}
2018-02-01 11:50:30 +00:00
Matt Falkenhagen
82a076e04a Revert "Remove all remaining deprecated Web/BrowserThreads!!"
This reverts commit 6127a86f3a.

Reason for revert: Suspect this caused spike in ThreadWatcher hang reports: crbug.com/768886

Original change's description:
> Remove all remaining deprecated Web/BrowserThreads!!
> 
> (except BrowserThread::FILE which has a handful use cases left still and
> will follow suit shortly)
> 
> (BrowserThread::PROCESS_LAUNCHER migration was put on hold because of
> Android specific requirements around process launching)
> 
> Remaining usage of TestBrowserThreadBundle::REAL_DB_THREAD could simply
> be removed as all of the product code was already migrated to TaskScheduler
> which always uses real threads in unit tests.
> 
> Bug: 689520, 365909, 752144
> Cq-Include-Trybots: master.tryserver.chromium.android:android_cronet_tester
> Change-Id: Id70b722aa35e8568795d5aac16947392ac1597be
> 
> NOPRESUBMIT=True (for content/browser/browser_thread_impl.cc:211)
> 
> Change-Id: Id70b722aa35e8568795d5aac16947392ac1597be
> Reviewed-on: https://chromium-review.googlesource.com/610880
> Reviewed-by: Alexei Svitkine <asvitkine@chromium.org>
> Reviewed-by: John Abd-El-Malek <jam@chromium.org>
> Reviewed-by: Dirk Pranke <dpranke@chromium.org>
> Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
> Commit-Queue: Gabriel Charette <gab@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#503732}

TBR=gab@chromium.org,jam@chromium.org,dpranke@chromium.org,asvitkine@chromium.org,sdefresne@chromium.org

# Not skipping CQ checks because original CL landed > 1 day ago.

NOPRESUBMIT=True (for restoring the deprecated browser threads)

Bug: 689520, 365909, 752144, 768886
Change-Id: I53d93572118303743e1dde71b2a473350717b215
Cq-Include-Trybots: master.tryserver.chromium.android:android_cronet_tester
Reviewed-on: https://chromium-review.googlesource.com/689254
Commit-Queue: Matt Falkenhagen <falken@chromium.org>
Reviewed-by: Matt Falkenhagen <falken@chromium.org>
Cr-Commit-Position: refs/heads/master@{#504939}
2017-09-28 08:08:19 +00:00
Gabriel Charette
6127a86f3a Remove all remaining deprecated Web/BrowserThreads!!
(except BrowserThread::FILE which has a handful use cases left still and
will follow suit shortly)

(BrowserThread::PROCESS_LAUNCHER migration was put on hold because of
Android specific requirements around process launching)

Remaining usage of TestBrowserThreadBundle::REAL_DB_THREAD could simply
be removed as all of the product code was already migrated to TaskScheduler
which always uses real threads in unit tests.

Bug: 689520, 365909, 752144
Cq-Include-Trybots: master.tryserver.chromium.android:android_cronet_tester
Change-Id: Id70b722aa35e8568795d5aac16947392ac1597be

NOPRESUBMIT=True (for content/browser/browser_thread_impl.cc:211)

Change-Id: Id70b722aa35e8568795d5aac16947392ac1597be
Reviewed-on: https://chromium-review.googlesource.com/610880
Reviewed-by: Alexei Svitkine <asvitkine@chromium.org>
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: Dirk Pranke <dpranke@chromium.org>
Reviewed-by: Sylvain Defresne <sdefresne@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#503732}
2017-09-22 14:33:59 +00:00
Gabriel Charette
a1e0a375eb Remove now unused BrowserThread's BlockingPool!!!
Bug: 667892
Change-Id: I98f41c80f6f7e041db2fa3713d531ce8db9932ec
Reviewed-on: https://chromium-review.googlesource.com/664219
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Reviewed-by: Robert Liao <robliao@chromium.org>
Commit-Queue: Gabriel Charette <gab@chromium.org>
Cr-Commit-Position: refs/heads/master@{#502004}
2017-09-14 18:48:21 +00:00
Francois Doray
dc4e108d99 Revert "Remove BrowserThread::FILE_USER_BLOCKING/CACHE/DB."
This reverts commit abd57f32d8.

Reason for revert: Will reland similar CL once the FILE thread is also deprecated (we prefer to deprecate all browser threads at once).

Original change's description:
> Remove BrowserThread::FILE_USER_BLOCKING/CACHE/DB.
> 
> These threads are deprecated and no longer used.
> 
> NOPRESUBMIT=true
> 
> Bug: 689520
> Change-Id: I55b05b70626f91c8a71d56642c851bb786dbfcaa
> Reviewed-on: https://chromium-review.googlesource.com/660597
> Reviewed-by: John Abd-El-Malek <jam@chromium.org>
> Commit-Queue: Francois Doray <fdoray@chromium.org>
> Cr-Commit-Position: refs/heads/master@{#501245}

TBR=jam@chromium.org,fdoray@chromium.org

Change-Id: I4a0605974792092af8780595fcccef5a6dda3d87
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: 689520
Reviewed-on: https://chromium-review.googlesource.com/663598
Reviewed-by: Francois Doray <fdoray@chromium.org>
Commit-Queue: Francois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501263}
2017-09-12 14:08:54 +00:00
Francois Doray
abd57f32d8 Remove BrowserThread::FILE_USER_BLOCKING/CACHE/DB.
These threads are deprecated and no longer used.

NOPRESUBMIT=true

Bug: 689520
Change-Id: I55b05b70626f91c8a71d56642c851bb786dbfcaa
Reviewed-on: https://chromium-review.googlesource.com/660597
Reviewed-by: John Abd-El-Malek <jam@chromium.org>
Commit-Queue: Francois Doray <fdoray@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501245}
2017-09-12 12:39:30 +00:00
Brett Wilson
abbb960461 Move Location and GetProgramCounter to base namespace
This maintains some forward declarations so all >400 uses don't need to be
updated at the same time.

This patch changes all forward declarations and code that depends on them.

BUG=763556
TBR=stevenjb@chromium.org (chromeos/network)

Cq-Include-Trybots: master.tryserver.chromium.android:android_optional_gpu_tests_rel;master.tryserver.chromium.linux:linux_optional_gpu_tests_rel;master.tryserver.chromium.mac:mac_optional_gpu_tests_rel;master.tryserver.chromium.win:win_optional_gpu_tests_rel
Change-Id: Icabd948fe9e0881fdb60db38b31a9d0763867bc4
Reviewed-on: https://chromium-review.googlesource.com/657249
Reviewed-by: Brett Wilson <brettw@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Brett Wilson <brettw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#501092}
2017-09-11 23:26:39 +00:00
tzik
6e42784f92 Migrate base::TaskRunner from Closure to OnceClosure
After this CL, TaskRunner::PostTask and its family can take OnceClosure
in addition to Closure.

Most of the changes are mechanical replacement of Closure with OnceClosure
on TaskRunner family. Others are:
 - Limit CriticalClosure from Closure to OnceClosure as no caller call
   the resulting callback more than once
 - Add several PostTaskAndReplyWithResult overloads for old Callback
   version, for compatibility. (in base/task_scheduler/post_task.h)
 - Update SequencedWorkerPool implementation for OnceClosure.
 - Update task handling code in app_state.mm for OnceClosure, which is
   needed to bring OnceClosure into a ObjC block.

BUG=704027
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel

Review-Url: https://codereview.chromium.org/2637843002
Cr-Commit-Position: refs/heads/master@{#462023}
2017-04-05 10:13:21 +00:00
tzik
070c8ffb44 Pass Callback to TaskRunner by value and consume it on invocation
This is a preparation CL for http://crrev.com/2637843002, which replaces
the Callback parameter of TaskRunner::PostTask with OnceCallback.
This one replaces the passed-by-const-ref Callback parameter of
TaskRunner::PostTask() with pass-by-value.

With the pass-by-const-ref manner as the old code does, we can't avoid
leaving a reference to the callback object on the original thread. That
is, the callback object may be destroyed either on the target thread or
the original thread. That's problematic when a non-thread-safe object is
bound to the callback.

Pass-by-value and move() in this CL mitigate the nondeterminism: if the
caller of TaskRunner::PostTask() passes the callback object as rvalue,
TaskRunner::PostTask() leaves no reference on the original thread.
I.e. the reference is not left if the callback is passed directly from
Bind(), or passed with std::move() as below.

  task_runner->PostTask(FROM_HERE, base::Bind(&Foo));

  base::Closure cb = base::Bind(&Foo);
  task_runner->PostTask(FROM_HERE, std::move(cb));

Otherwise, if the caller passes the callback as lvalue, a reference to
the callback is left on the original thread as we do in the previous code.
I.e. a reference is left if the callback is passed from other non-temporary
variable.

  base::Closure cb = base::Bind(&Foo);
  task_runner->PostTask(FROM_HERE, cb);

This is less controversial part of http://crrev.com/2637843002. This CL
is mainly to land it incrementally.

TBR=shrike@chromium.org
BUG=704027
CQ_INCLUDE_TRYBOTS=master.tryserver.blink:linux_trusty_blink_rel

Review-Url: https://codereview.chromium.org/2726523002
Cr-Commit-Position: refs/heads/master@{#460288}
2017-03-29 05:28:12 +00:00
gab
3ee0e445ae Experiment with redirecting all BrowserThreads (but UI/IO) to TaskScheduler
This is part of the migration phase for TaskScheduler, design doc:
https://docs.google.com/document/d/1S2AAeoo1xa_vsLbDYBsDHCqhrkfiMgoIPlyRi6kxa5k/edit

Also generalizes BrowserThreadImpl away from the underlying thread's MessageLoop
and id in favor of TaskRunners and BrowserThreadState.

Cool side-effect: BrowserThreadImpl::StartWithOptions() no longer blocks on the
underlying thread starting (it used to via GetThreadId()), it now takes a reference
to its TaskRunner and lets the thread itself start on its own schedule :).
This wasn't previously intended to block (BrowserThreadImpl::StartAndWaitForTesting() is
supposed to be used for that) but had unintentionally regressed in http://crrev.com/408295
because GetThreadId() implicitly waits (http://crbug.com/672977).

Another nice improvement is that ~BrowserThreadImpl() now cleans the BrowserThreadGlobals
associated with it, this has the side-effect to force proper destruction order of
TestBrowserThread in tests which brought forth a few precursor cleanups
(https://crbug.com/653916#c24) which will from now on be enforced by this CL.

When redirection is disabled, the logic should be the exact same as before.
 - Threads are brought up.
 - Tasks are posted to their MessageLoop (albeit through their TaskRunner now).
 - On shutdown, threads are joined one by one.

When redirection is enabled, we try to mimic this logic.
 - Redirection TaskRunners are only live (|accepting_tasks|) for the same period that the
   matching thread would be.
 - On shutdown, we block on each TaskRunner's queue being flushed one-by-one
   in the same order as in the no-redirection case (this almost identical to
   real threads join % one slight difference documented in detail in
   BrowserThreadImpl::StopRedirectionOfThreadID()).

BUG=653916, 672977
CQ_INCLUDE_TRYBOTS=master.tryserver.chromium.linux:linux_chromium_tsan_rel_ng

TEST=
 A) "out\Release\chrome.exe"
    Runs/shuts down the exact same as before.

 B) "out\Release\chrome.exe --force-fieldtrials=BrowserScheduler/Enabled/ --force-fieldtrial-params=BrowserScheduler.Enabled:Background/3;3;1;0;10000/BackgroundFileIO/3;3;1;0;10000/Foreground/3;3;1;0;10000/ForegroundFileIO/3;3;1;0;10000/RedirectSequencedWorkerPools/true/RedirectNonUINonIOBrowserThreads/true"
    Runs/shuts down smoothly and chrome://tracing confirms that redirected BrowserThreads are running on TaskSchedulerWorkers.

Review-Url: https://codereview.chromium.org/2464233002
Cr-Commit-Position: refs/heads/master@{#439139}
2016-12-16 17:46:20 +00:00
gab
606d46cc6d Remove direct usage of BrowserThreadImpl in tests
Instantiating a BrowserThreadImpl sets global state which leaks to the next
tests. This is a problem in https://codereview.chromium.org/2464233002/ where
a reset was introduced for tests (driven by TestBrowserThread).

Tests should already have been using TestBrowserThread over BrowserThreadImpl
and today TestBrowserThreadBundle is favored over TestBrowserThread so it is
used as the replacement in this CL.

BUG=653916

Review-Url: https://codereview.chromium.org/2487073005
Cr-Commit-Position: refs/heads/master@{#431070}
2016-11-09 23:15:35 +00:00
rockot
48a6aacd38 Ensure BrowserThread::CurrentlyOn is correct through MessageLoop teardown
Changes BrowserThread::CurrentlyOn (and thus
BrowserThreadTaskRunner::RunsTasksOnCurrentThread()) to correctly report
a BrowserThread's association during MessageLoop destruction notification.

Also adds an explicit Start() to BrowserThreadImpl as there are tests which
call it and which incorrectly assumed base::Thread's implementation would
call BrowserThreadImpl::StartWithOptions (which it wouldn't since the latter
is not a virtual function.)

This change provokes many tests to delete ExtensionFunction instances that
were otherwise being leaked because UIThreadExtensionFunction::Destroy was
incorrectly deferring destruction when run on the UI thread during shutdown.
This in turn revealed a few small bugs which have also been fixed here.

BUG=631093
R=jam@chromium.org

Committed: https://crrev.com/b02da29fb9116d1a1fb4fd0476628f333ff6bd1a
Review-Url: https://codereview.chromium.org/2180253003
Cr-Original-Commit-Position: refs/heads/master@{#408295}
Cr-Commit-Position: refs/heads/master@{#408411}
2016-07-28 17:25:20 +00:00
rockot
dd05854bb5 Revert of Ensure BrowserThread::CurrentlyOn is correct through MessageLoop teardown (patchset id:160001 of https://codereview.chromium.org/2180253003/ )
Reason for revert:
Test failures in the changes to the ComponentCloudPolicyTest. Doh.

Original issue's description:
> Ensure BrowserThread::CurrentlyOn is correct through MessageLoop teardown
>
> Changes BrowserThread::CurrentlyOn (and thus
> BrowserThreadTaskRunner::RunsTasksOnCurrentThread()) to correctly report
> a BrowserThread's association during MessageLoop destruction notification.
>
> Also adds an explicit Start() to BrowserThreadImpl as there are tests which
> call it and which incorrectly assumed base::Thread's implementation would
> call BrowserThreadImpl::StartWithOptions (which it wouldn't since the latter
> is not a virtual function.)
>
> This change provokes many tests to delete ExtensionFunction instances that
> were otherwise being leaked because UIThreadExtensionFunction::Destroy was
> incorrectly deferring destruction when run on the UI thread during shutdown.
> This in turn revealed a few small bugs which have also been fixed here.
>
> BUG=631093
> R=jam@chromium.org
>
> Committed: https://crrev.com/b02da29fb9116d1a1fb4fd0476628f333ff6bd1a
> Cr-Commit-Position: refs/heads/master@{#408295}

TBR=jam@chromium.org
# Skipping CQ checks because original CL landed less than 1 days ago.
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
BUG=631093

Review-Url: https://codereview.chromium.org/2186213002
Cr-Commit-Position: refs/heads/master@{#408311}
2016-07-28 02:06:31 +00:00
rockot
b02da29fb9 Ensure BrowserThread::CurrentlyOn is correct through MessageLoop teardown
Changes BrowserThread::CurrentlyOn (and thus
BrowserThreadTaskRunner::RunsTasksOnCurrentThread()) to correctly report
a BrowserThread's association during MessageLoop destruction notification.

Also adds an explicit Start() to BrowserThreadImpl as there are tests which
call it and which incorrectly assumed base::Thread's implementation would
call BrowserThreadImpl::StartWithOptions (which it wouldn't since the latter
is not a virtual function.)

This change provokes many tests to delete ExtensionFunction instances that
were otherwise being leaked because UIThreadExtensionFunction::Destroy was
incorrectly deferring destruction when run on the UI thread during shutdown.
This in turn revealed a few small bugs which have also been fixed here.

BUG=631093
R=jam@chromium.org

Review-Url: https://codereview.chromium.org/2180253003
Cr-Commit-Position: refs/heads/master@{#408295}
2016-07-28 00:44:34 +00:00
fdoray
e1e050c52c Remove calls to MessageLoop::current() in base.
Why?
The fact that there's a MessageLoop on the thread is an
unnecessary implementation detail. When browser threads
are migrated to base/task_scheduler, tasks will no longer
have access to a MessageLoop.

These changes were generated manually.

Note: Some files outside of base/ had to be modified
because they didn't compile anymore after
#include "base/message_loop/message_loop.h" was removed
from base/ headers.

BUG=616447
TBR=rogerta@chromium.org

Review-Url: https://codereview.chromium.org/2136563002
Cr-Commit-Position: refs/heads/master@{#406378}
2016-07-19 21:07:53 +00:00
kinuko
7f68f87353 Reland (3rd try): Lazily initialize MessageLoop for faster thread startup
Original review: https://codereview.chromium.org/1011683002/
2nd try: https://codereview.chromium.org/1129953004/

2nd try reverted due to race reports on Linux:
https://crbug.com/489263 Data races on valid_thread_id_ after r330329

This fixes:
- Race in MessageLoopProxyImpl by introducing lock
- Race in BrowserMainLoop/BrowserThreadImpl, where BrowserThread::CurrentlyOn()
  called on one of BrowserThreads tries to touch other thread's message_loop()
  via global thread table.

Reg: the latter race, the code flow that causes this race is like following:

  // On the main thread, we create all known browser threads:
  for (...) {
    {
      AutoLock lock(g_lock);
      g_threads[id] = new BrowserProcessSubThread();
    }
    // [A] This initializes the thread's message_loop, which causes a race
    // against [B] in the new code because new threads can start running
    // immediately.
    thread->StartWithOptions();
  }

  // On the new thread's main function, it calls CurrentlyOn() which does:
  {
    // [B] This touches other thread's Thread::message_loop.
    AutoLock lock(g_lock);
    return g_threads[other_thread_id] &&
           g_threads[other_thread_id]->message_loop() == MessageLoop::current();
  }

This was safe before because both message_loop initialization and the first
call to CurrentlyOn() on the new thread was done synchronously in
StartWithOptions() while the main thread was blocked. In the new code
new threads can start accessing message_loop() asynchronously while
the main thread's for loop is running.

PS1 is the original patch (2nd try) that got reverted.

BUG=465458, 489263

Review URL: https://codereview.chromium.org/1131513007

Cr-Commit-Position: refs/heads/master@{#331235}
2015-05-23 11:39:08 +00:00
dcheng
c2282aa891 Standardize usage of virtual/override/final in content/browser/
This patch was automatically generated by applying clang fixit hints
generated by the plugin to the source tree.

BUG=417463
TBR=sky@chromium.org

Review URL: https://codereview.chromium.org/667943003

Cr-Commit-Position: refs/heads/master@{#300469}
2014-10-21 12:08:25 +00:00
mohan.reddy
7fc3ac7d5a Replace FINAL and OVERRIDE with their C++11 counterparts in content
This step is a giant search and replace for OVERRIDE and FINAL to
replace them with their lowercase versions.

BUG=417463

Review URL: https://codereview.chromium.org/637183002

Cr-Commit-Position: refs/heads/master@{#298804}
2014-10-09 05:24:24 +00:00
jkarlin
80e53817d6 Flush SimpleCache worker pool between all tests.
This will prevent tests that utilize a SimpleCache from running into teardown leaks.

BUG=413688

Review URL: https://codereview.chromium.org/562203002

Cr-Commit-Position: refs/heads/master@{#296936}
2014-09-26 14:33:02 +00:00
earthdok@chromium.org
b5217d5338 Flush the blocking pool in TestBrowserThreadBundle.
While we already flush the blocking pool in a OnTestEnd() hook (installed in
ContentTestSuiteBase), that is too late for tests that create their own threads.
The test (and the TestBrowserThreadBundle that it contains) will have been
destroyed by the time the hook runs, and any tasks posted to the blocking pool
via PostTaskAndReply will not be able to reply back to the originating thread.
This causes the task and reply Closures to be leaked. Flushing the blocking pool
before TestBrowserThreadBundle is destroyed should fix those leaks.

BUG=168415, 270673, 270658
TBR=ajwong@chromium.org, jochen@chromium.org

Review URL: https://codereview.chromium.org/22799005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217268 0039d316-1c4b-4281-b951-d872f2087c98
2013-08-13 16:06:21 +00:00
jamesr@chromium.org
08dda5ce86 Remove unused WEBKIT_DEPRECATED thread
BUG=237267, 234283
R=jam@chromium.org

Review URL: https://codereview.chromium.org/18414007

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@212661 0039d316-1c4b-4281-b951-d872f2087c98
2013-07-19 21:55:53 +00:00
ajwong@chromium.org
ec04d3f550 Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads.
This CL creates a new class, TestBrowserThreadBundle, that creates a TestBrowserThread for the most commonly needed BrowserThreads. It also adds this thread bundle into RenderViewHostTestHarness because most tests that use this harness need these threads in order to run.  To support TestBrowserThreadBundle, BrowserThreadImpl's test construction was also modified to understand a NULL message_loop.

Aside from introducing the new class, this CL also removes:
  (1) unnecessary constructors in test
  (2) DISALLOW_COPY_AND_ASSIGNS in test fixtures*
  (3) now redundant TestBrowserThreads from tests
  (4) bad access-level changes for SetUp() and TearDown()
  (5) using declarations that root off the global scope
  (6) uses of MessageLoop's RunUntilIdle() and Quit()
  (7) as many real threads as possible

There are also a changes to MediaCaptureDevicesDispatcher and OneClickSigninHelper that allow unittests to cut dependencies on IO thread activity.  DesktopNotificationServiceTest (and a couple of others) were also made single threaded because the synchronization logic required for a non-flaky test meant the parallelism only really exercised the extra code in the test that forced the serialization.

* DISALLOW_COPY_AND_ASSIGN does not serve much purpose in GTest fixture types. However, using it removes the compile-provided default constructor which forces the fixture writer to provide an empty default constructor. Since GTest recommends the default constructor as the preferred method to do setup for a test (as opposed to the SetUp() method), it's confusing to have bunch of classes with both SetUp() and a default constructor. It's simpler and uses less code to just remove the DISALLOW_COPY_AND_ASSIGN. An alternative would be to use the default constructor for initialization, but this is not possible because of our test harnesses are inheritance based which means it is impossible for a derived fixture to perform initialization before the harness if we use the GTest preferred default constructor initialization pattern.

TBR=avi,battre,ben,benwells,brettw,dbeam,dimich,joi,joth,mad,marja,markusheintz,noelallen,phajdan,rdsmith,satorux,scherkus,sky,stevenjb,stuartmorgan,timsteele
BUG=159193

Review URL: https://chromiumcodereview.appspot.com/14197014

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@204603 0039d316-1c4b-4281-b951-d872f2087c98
2013-06-06 21:31:39 +00:00
xhwang@chromium.org
dd32b127ce content: Use base::MessageLoop.
BUG=236029
R=avi@chromium.org

Review URL: https://chromiumcodereview.appspot.com/14335017

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@198316 0039d316-1c4b-4281-b951-d872f2087c98
2013-05-04 14:17:11 +00:00
michaeln@google.com
13ecb5e99e Flush SequenceWorkerPool tasks after each test. Applies to unit_test, interactive_ui test, browser_tests... pretty much all gtest based content library test harnesses are affected.
The CL changes semantics and implementation of the existing FlushForTesting method (which wasn't suitable for this usage).

* The old method would wait for delayed tasks prior to continuing, the new method
will not run them but will delete them prior to continuing.

* The old method would deadlock if called after Shutdown had been called, the new method returns immediately in that case.

A few SWP unittests relied on the waiting for delayed task completion behavior. Those have been modified to explicitly wait thru other means.

BUG=168415,166470
Review URL: https://codereview.chromium.org/11649032

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@186578 0039d316-1c4b-4281-b951-d872f2087c98
2013-03-07 01:35:37 +00:00
tfarina@chromium.org
0f591eee6f content: Remove deprecated method from TestBrowserThread.
TEST=content_unittests
R=jam@chromium.org


Review URL: https://chromiumcodereview.appspot.com/11881025

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@177327 0039d316-1c4b-4281-b951-d872f2087c98
2013-01-17 03:02:40 +00:00
rtenneti@google.com
e0b87aa21c Added unique function names (IOThreadRun, DBThreadRun, etc)
which make it possible to tell the thread name in crash dumps
from the call stack. Added a volatile automatic variable to
avoid global optimizers optimizing the function.

This change would help us to triage ThreadWatcher crashes
for IO thread. It would also help in debugging crashes.

R=sky, jar
Review URL: https://chromiumcodereview.appspot.com/10796079

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@147949 0039d316-1c4b-4281-b951-d872f2087c98
2012-07-23 21:21:23 +00:00
ajwong@chromium.org
f78671752a Remove #pragma once from content
Review URL: https://chromiumcodereview.appspot.com/10696166

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146071 0039d316-1c4b-4281-b951-d872f2087c98
2012-07-11 07:04:07 +00:00
thestig@chromium.org
9226938bf4 Cleanup: IWYU for BrowserThread.
BUG=none
TEST=none

Review URL: http://codereview.chromium.org/9558012

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@124852 0039d316-1c4b-4281-b951-d872f2087c98
2012-03-03 09:00:08 +00:00
tedvessenes@gmail.com
17dc674a9c Add functions to expand PostDelayedTask interface.
These functions add TimeDelta interfaces in addition to the int ms interfaces,
which will be removed at a later date.

BUG=108171


Review URL: http://codereview.chromium.org/9427023

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123683 0039d316-1c4b-4281-b951-d872f2087c98
2012-02-26 08:17:37 +00:00
brettw@chromium.org
3189013eeb Hook up the SequencedWorkerPool to the browser thread.
[re-land of 116816 http://codereview.chromium.org/9065009]

This does some refactoring of the static data in the browser thread so we only have one global object instead of a bunch fo separate arrays.

It also hooks up the visited link master's I/O to use this new system as a proof of concept.
Review URL: https://chromiumcodereview.appspot.com/9124033

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@118236 0039d316-1c4b-4281-b951-d872f2087c98
2012-01-19 04:11:57 +00:00